Please see this code
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$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
I had the same issue with ec2 for php mail.
Solution worked for me:
install sendmail by command:
check the service whether its started or not by execuring follwing command
Note: Output of above command should be something -
'Active: active (running)'
start the service if it is not running by following command
After the service is started, send a test mail using following command:
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/.
Amazon server allow sendmail functionality using localhost. Please uncomment mail configuration in php.ini.
I have already done this and working fine.
Apparently sending PHP from EC2 is not possible until it gets unlocked by support. To unlock it visit: EC2 - Fresh PHP install - Mail not working
Otherwise, i will just quote @Charles answer:
So - no you can't send, but use Simple Email Service, libraries like SwiftMailer, or I would add services like SendGrid
*Source: Another SO question on php mail & EC2
MEANWHILE: I signed up for Simple Email Service, which is somewhat what SendGrid is doing. It's was very simple. First you request smtp user and password. You then either confirm an email for testing, or request production access [I didn't need that so I haven't gone through process]. And one caveat - use
ssl://
in front of the host, or it will give youSMTP error: 530 5.7.0 Must issue a STARTTLS command first.
error. I was using CakePHP and EC2 when this happened.Just follow instructions below (Tested for ubuntu 10x EC2)
Enjoy!
I'd had the same issue as you in sending an email using Php's
mail()
. Installing send mail solved it for me.are you willing to use other mailing framework? If yes, you can use phpmailer...it works fine for me.
here is the link on their site. http://phpmailer.worxware.com/