Now days, for a mail server to send an email, either (or both) the To: email address or the From: email address must be hosted at the sending mail server (email address has the same domain name as the hosting/mail server) or the sending mail server must has an SPF dns record that indicates the sending mail server is authorized to send email for the domain in the From: email address, otherwise the sending mail server thinks you are trying to relay email through it without proper authorization.
You can get a mail server to accept and send an email when both the To: and From: email addresses don’t meet the conditions mentioned above, by using SMTP authentication, and essentially ‘login’ to your account at the mail server, which the php mail() function doesn’t support. To use SMTP authentication, you will either need to exchange smtp commands directly with the mail server (requires that you write and test a bunch of code) or more simply use one of the php mailer classes - phpmailer or swiftmailer, which will do this for you.
Depending on what your application is trying to accomplish with these emails, you can either make sure that one (or both) of the To: or From: email addresses is hosted at the sending mail server or you have a properly set up SPF dns record or you need to use SMTP authentication.
So, what exactly are these emails for?
Note: A common mistake is to use an email address that is entered in a ‘contact us’ form as the From: email address. This is not correct. These emails are NOT being sent from the email addresses that someone entered in a form and this doesn’t satisfy the conditions I have listed above and can cause the error you are receiving.