user3161300
user3161300

Reputation: 11

EC2 SES from php mail

Sending emails to SES

When I do the following command from command prompt it works and successfully sends email

sudo /usr/sbin/sendmail -f test@gmail.com test@gmail.com

I followed these instruction http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sendmail.html

When I try the same from a simple php app here is what I get back “Service Unavailable”

Jan  4 20:58:58 ip-10-252-22-51 sendmail[32217]: s04Kww8t032217: from=www-data, size=130, class=0, nrcpts=1, msgid=<201401042058.s04Kww8t032217@ip-10-252-22-51.us-west-2.compute.internal>, relay=www-data@localhost
Jan  4 20:58:58 ip-10-252-22-51 sm-mta[32218]: s04Kww3h032218: from=<www-data@ip-10-252-22-51.us-west-2.compute.internal>, size=475, class=0, nrcpts=1, msgid=<201401042058.s04Kww8t032217@ip-10-252-22-51.us-west-2.compute.internal>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jan  4 20:58:58 ip-10-252-22-51 sendmail[32217]: s04Kww8t032217: to=test@gmail.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30130, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (s04Kww3h032218 Message accepted for delivery)
Jan  4 20:58:59 ip-10-252-22-51 sm-mta[32220]: STARTTLS=client, relay=email-smtp.us-east-1.amazonaws.com, version=TLSv1/SSLv3, verify=FAIL, cipher=AES256-SHA, bits=256/256
Jan  4 20:59:00 ip-10-252-22-51 sm-mta[32220]: s04Kww3h032218: to=<sinkinsona@gmail.com>, ctladdr=<www-data@ip-10-252-22-51.us-west-2.compute.internal> (33/33), delay=00:00:02, xdelay=00:00:02, mailer=relay, pri=120475, relay=email-smtp.us-east-1.amazonaws.com [23.21.252.142], dsn=5.0.0, stat=Service unavailable
Jan  4 20:59:00 ip-10-252-22-51 sm-mta[32220]: s04Kww3h032218: s04Kx03h032220: DSN: Service unavailable
Jan  4 20:59:00 ip-10-252-22-51 sm-mta[32220]: s04Kx03h032220: to=<www-data@ip-10-252-22-51.us-west-2.compute.internal>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

In my php.ini sendmail points to

/usr/sbin/sendmail –t –i

I have added apache user to mail.

sudo adduser www-data mail

Here is the contents of my test php file

$to = "test@gmail.com";
$subject = "test mail";
$message = "hello - this is a test";
$headers ="From: test@gmail.com";
mail($to,$subject,$message,$headers);
echo "Mail Sent";

Any help on why I cannot send emails from php mail function would be much appreciated.

Upvotes: 1

Views: 1925

Answers (2)

Pickledip
Pickledip

Reputation: 21

Specify the sender envelope/return-path add the "-f" parameter. Best, especially with SES, to have the "from:" header match that of the sender:

$to = "test@gmail.com";
$subject = "test mail";
$message = "hello - this is a test";
$headers ="From: test@gmail.com";
$params = "-ftest@gmail.com"
mail($to,$subject,$message,$headers,$params);
echo "Mail Sent";

Upvotes: 2

Sven Delmas
Sven Delmas

Reputation: 822

I just ran into this (or something like this) myself. I found that specifying the from email address on the sendmail command line (inside of php.ini) resolved this for me:

/usr/sbin/sendmail –t –i -f from_email_address

So it seems like that is not properly added to the request.

Upvotes: 1

Related Questions