Please see this code
<?php
$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.";
?>
what is the problem in this code . Its not working on Amazon Linux server
Thanks
If it's still not working: change the sender ($sender) to a local email (use the same email as used for recipient). Upload the modified php file and retry. Contact your provider if it still does not work. Tell your provider that the standard php "mail()" function returns TRUE, but not mail will be sent.
Unless you mean delivering mail to the webmaster, it doesn't make sense for the webmaster to configure things. You're asking the wrong question - there is nothing wrong with the mail() function in PHP - it's not unreliable. The problem is contents and distribution of your mails.
The mail() function allows you to send emails directly from a script.
I had the same issue with ec2 for php mail.
Solution worked for me:
install sendmail by command:
sudo apt-get install sendmail
check the service whether its started or not by execuring follwing command
service sendmail status
Note: Output of above command should be something - 'Active: active (running)'
start the service if it is not running by following command
service sendmail start
After the service is started, send a test mail using following command:
echo "This is test mail body" | mail -s "Test Mail Subject" "[email protected]"
Replace email with your email ID and see if you receive this email, if yes, then your mail setup is fine and now your php email should be working fine.
If not, file to check for errors is /var/spool/mail/.
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
Amazon server allow sendmail functionality using localhost. Please uncomment mail configuration in php.ini.
I have already done this and working fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With