There are few reasons and you need to solve all of them before an email can be sent from AWS Lightsail Wordpress template.
By default, AWS blocks the port for sending email from EC2 instance (Lightsail is an EC2 instance behind the scene). Solution: Submit a ticket to AWS and ask them to unblock the email restriction on the server
The sendmail package is NOT installed in the Lightsail Wordpress template by default. Solution: sudo apt-get install sendmail to install sendmail. After this step, you can see sendmail in /usr/sbin
Sending email to a specific domain like [email protected]may result in “stat=User unknown“ error shown in /var/log/mail.log. Reason: your domain name matches either your server’s hostname or a setting in sendmail’s config file. Solution: Configure sendmail to force send emails to your actual mail server instead of itself by editing /etc/mail/sendmail.mc and add the following lines:
sudo sendmailconfig to configure sendmail with the updated setting and press ‘Y’ for all default when prompted
Update /opt/bitnami/php/etc/php.ini by enabling sendmail_path: env -i /usr/sbin/sendmail -t -i. Remember to remove the prefix ";" in the beginning of the line.
Make sure the host name is list in in the host file /etc/hosts, e.g. 127.0.0.1 localhost myhostname
Restart server sudo /opt/bitnami/ctlscript.sh restart
Restart php-fpm service sudo /opt/bitnami/ctlscript.sh restart php-fpm
If you’ve used the WordPress-specific package in Lightsail to create your site, you should be able to send email just by adding in an SMTP plugin and connecting it to either a transactional email service like SendGrid or Postmark, or connecting it to an existing SMTP server via username and password.
In my experience, I’ve not found it necessary to open up ports or anything server-level when using the WordPress Lightsail image.
For the plugin, personally, I love FluentSMTP for this as it makes things simple, gives you lots of features, and it’s free 😉
The route I usually go is then to create a free SendGrid account, add your sending domain to it, and then you have to verify it by adding a few records to your DNS zone for the domain.
2
Answers
There are few reasons and you need to solve all of them before an email can be sent from AWS Lightsail Wordpress template.
sudo apt-get install sendmail
to install sendmail. After this step, you can see sendmail in/usr/sbin
/var/log/mail.log
. Reason: your domain name matches either your server’s hostname or a setting in sendmail’s config file. Solution: Configure sendmail to force send emails to your actual mail server instead of itself by editing/etc/mail/sendmail.mc
and add the following lines:Make sure to (1) change your own domain name (2) ended with the trailing dot! Reference and credit to: https://tecadmin.net/sendmail-user-unknown-error-resolved/
sudo sendmailconfig
to configure sendmail with the updated setting and press ‘Y’ for all default when prompted/opt/bitnami/php/etc/php.ini
by enablingsendmail_path: env -i /usr/sbin/sendmail -t -i
. Remember to remove the prefix ";" in the beginning of the line./etc/hosts
, e.g.127.0.0.1 localhost myhostname
sudo /opt/bitnami/ctlscript.sh restart
sudo /opt/bitnami/ctlscript.sh restart php-fpm
If you’ve used the WordPress-specific package in Lightsail to create your site, you should be able to send email just by adding in an SMTP plugin and connecting it to either a transactional email service like SendGrid or Postmark, or connecting it to an existing SMTP server via username and password.
In my experience, I’ve not found it necessary to open up ports or anything server-level when using the WordPress Lightsail image.
For the plugin, personally, I love FluentSMTP for this as it makes things simple, gives you lots of features, and it’s free 😉
https://fluentsmtp.com/
The route I usually go is then to create a free SendGrid account, add your sending domain to it, and then you have to verify it by adding a few records to your DNS zone for the domain.
https://docs.sendgrid.com/ui/account-and-settings/how-to-set-up-domain-authentication
Once all that’s complete, generate an API key from SendGrid and enter it into FluentSMTP’s settings:
https://fluentsmtp.com/docs/set-up-the-sendgrid-driver-in-fluent-smtp/
Should be good to go at that point!