简体   繁体   中英

How to send mail from aws server using php mail()?

Using php mail() I am able to send email from cpanel but the same code is not working in aws server. below is my code.

$to="mymail@gmail.com";
$subject="Hello";
$message="Welcome Onboard";
$headers  = "From:Test<test@gmail.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";

$retval = mail($to,$subject,$message,$headers);
return $retval;

You should be able to send sendmail() in AWS but the service needs to be up and running in your instance. Check this link on how to get that started.

Alternatively, you could use AWS SeS service, which works really well and is more robust. Check out this answer to see how that can be accomplished (pretty simple).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM