Search code examples
phpamazon-ec2

Simple PHP Mail function not working on Amazon server EC2


I have a PHP script that is supposed to send an email. The script works fine on my local machine, but when I run it on an Amazon Linux server, it doesn't send the email.

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

Solution

  • I'd had the same issue as you in sending an email using Php's mail(). Installing send mail solved it for me.

    sudo apt-get install sendmail