Just recently and by accident, I found out that I cannot send emails to foreign sources beyond my server (I’ve been testing it with local Email addresses being installed at the same server). This is my code and I cannot send to (e.g.) gmail or yahoo.
$receiver = $emailadr;
$subj = 'Auth';
$msg = 'Thank you!';
$header = 'From: [email protected]' . "rn" .
'Reply-To: [email protected]' . "rn" .
'X-Mailer: PHP/' . phpversion() . "rn" . 'Content-type: text/html; charset=iso-8859-1';
mail($receiver, $subj, $msg, $header);
When (attempting) sending, it comes up with this:
: mail(): SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
I’m using Plesk 12.5
2
Answers
Looks like a problem of the mailserver. Your codes is on a shared hosting? Your provider probably has an anti-spam configuration (hopefully). You have to make sure that your sender address is existing. For testing, it’s also helpful if you send the message to yourself (if you didn’t already), this has more chances to work and then you can check the mail headers.
On a average configured e-mail server, there are four ways of mail communication: (i assume your server is running somedomain.com and is providing @somedomain.com mails)
Error message is quite clear
This mail server requires authentication
You can create mail user in Plesk and use following PHP class to send mail with authentication:
http://phpmailer.worxware.com/index.php?pg=tutorial#2
Also you can try some cloud mail services like http://sendgrid.com/ they have nice PHP API library.