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'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
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" "recipient@email.com"
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.
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/
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:
This won't directly solve your issue (edit: I mean the error message
you have now edited out), but Amazon EC2 instances have a really
spotty mail reputation. You're probably going to have deliverability
issues.
Thankfully Amazon created the Simple Email Service to go along with
EC2, with a free level of service for EC2 customers. The API is pretty
simple and there are transport adapters for many excellent PHP mailing
libraries, like SwiftMailer (transport).
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 you SMTP 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)
sudo apt-get install php-pear // Install php-pear if not installed
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
sudo apt-get install postfix
sudo service apache2 restart
Enjoy!