I’ve followed the directions on this page to setup mail() on AWS linux ubuntu, but the mail function is not working. I know I’ve written the send mail script correctly, so is there something else I need in order for this to work? Is there a special webmail software or something I need?
EDIT:
display_errors is on. PHP code is as follows.
Success message is displayed, but the email is never received.
$to = "myemail@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body))
{
echo("Message successfully sent!");
}
else
{
echo("Message delivery failed...");
}
EDIT 2:
I tried sending it to an email hosted by godaddy and a gmail account. Both returned the same response below in the error log.
Error log:
“8C029: host smtp.secureserver.net[...] refused to talk to
me: ––*.... 554 Your access to this mail system has
been rejected due to the sending MTA’s poor reputation. If you believe
that this failure is in error, please contact the intended recipient
via alternate means.”
Nevermind, Gmail received the message 15 minutes later. I guess the two errors were both related to godaddy hosted email.
The error is indeed not originating in either your
mail()code or server setup — Your MTA receives the message from themailcommand and tries to deliver the message.The error originates from either GoDaddy’s receiving mail server (the one your postfix is trying to deliver the message to). Or one of the SMTP relaying servers along the route.
The rejection is not unexpected though: You stated that your server is running in AWS. Unfortunately you aren’t the only one mailing from AWS instances. A lot of notorious spammers have preceeded you, ruining AWS’ IP addresses’ credibility as trustworthy mail sources. This is why many ISP’s block incoming mail originating from AWS (Which is what the 554 error is: Relay access denied).
To worsen your problem: If you keep using this approach AWS will automatically block all outgoing mail from your instances in an attempt to counter the spam issue. After manual validation of your intent they should reinstate your mailing privileges however.
Your best option on AWS to reliably send email would probably be using their own SES service, which should probably get you past most RBL checks in MTA’s. But SES does cost money..