By using AWS re:Post, you agree to the Terms of Use

Sending emails from EC2 Ubuntu 22.04 server


I am running an Ubuntu 22.04 Server on an EC2 instance which is within the Free Tier. I want to be able to use the PHP mail() function which sends emails but uses the underlying OS mail functionality to do so. The mail() function is returning false which I think may be due to firewall / security group issues. However I also thought it may be that Amazon does not allow sending of emails from Free Tier accounts. It did work fine on my old Debian server which was not with Amazon although that was running an older version of PHP so that could be an issue. I can not see any log files relating to the attempts I have made to send emails (I looked under /var/log) which makes me think maybe I need to install an email program such as postfix or something.

I do not want to send a lot of emails as in marketing etc. At the moment it would only be a few a week.

I would like help troubleshooting this. Am I allowed to send emails? What port would they be sent on (and which therefore needs to be enabled)? Where are the logs? Do I need to install an email program? Any other ideas I have not thought of?

1 Answer

I have never had an issue sending mails from EC2 in free tier. Can you confirm you have setup sendmail_from and sendmail_path in your php.ini file? Included a link with additional information.

answered a month ago
  • I have just been reading about that and looking at my php.ini file. It says sendmail_from is for Win32 only. What should I put into sendmail_path? Do I need to install a mail program?

  • I do not have /usr/sbin/sendmail or /usr/sbin/postfix

  • Not entirely sure where you are at in the process but Install sendmail sudo apt install sendmail and make sure your local host is pointing to your hostname (/etc/hosts) localhost hostname (w/e that is for your ec2 instance). Then you should be able to just run sudo sendmailconfig refer to:

    Restart your apache (or NGINX) for good measure. Any additional issues that result in no logs are generally config related to your php.ini file (typos etc causing issues) and sendmail_path not being pointed to your sendmail package.

    postfix is just another package, like sendmail.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions