Why can't I use PHP's mail() function on this Bitnami server?

I've installed sendmail:

sudo apt-get install sendmail

And I've restarted the server:

sudo /opt/bitnami/ctlscript.sh restart apache

This has enabled mail() for me in the past, on non-bitnami servers.

But PHP's mail() function isn't working. We are using WordPress and need the ability to reset the password, which requires an email confirmation. Our server is an EC2 instance at Amazon.

Help!

We recommend not to use "sendmail" for sending emails. Amazon limits the number of the outgoing emails from the instances.

"In order to maintain the quality of EC2 addresses for sending email, we enforce default limits on the amount of email that can be sent from EC2 accounts"

We suggest to use a SMTP configuration with an email provider. You can find how to configure mail() function in a LAMP to send emails through a GMail account in the link below: http://wiki.bitnami.com/Components/PHP#How_to_send_email_via_external_SMTP_account

In the WordPress case, you can find a guide to configure with a plugin. You can find more info at:

http://wiki.bitnami.com/Applications/BitNami_Wordpress#How_to_configure_the_email_settings_of_WordPress.3f

I hope it helps.

Hi Beltran,

Thanks for weighing in.

I've had issues with Gmail. Apparently they limit the number of outgoing emails too — to 2,000 per day. We're actually coming close to that limit on another project.

I could go ahead and implement Gmail SMTP on our Bitnami server, though it'd be a hassle because I'd need to do it for each of our WordPress sites... when you say "we don't recommend sendmail" does that mean it cannot be implemented period? Or is there some magical line of code I need to run in the shell window to enable it?

Appreciate your help with this.

Yes, you can use "sendmail" tool but check the Amazon limits too. You can enable it in the main php.ini file:

sendmail_path = "env -i /usr/sbin/sendmail -t -i"

1 Like

Thanks man.

I've done this and now the server thinks the email has gone through successfully, but it never arrives at my inbox. Guess this is just the unreliability of not using SMTP?

Hi Martyn,

Have you detect anything unusual at /var/log/mail.log?

Regards.

What if I’m switching from sendmail to postfix, do I just comment out sendmail_path = “env -i /usr/sbin/sendmail -t -i” in php.ini?

Hi @bradley4681,

I think so.

Regards.

An update to anyone attempting to use mail() on a Bitnami server:

After adding (or uncommenting) sendmail_path = “env -i /usr/sbin/sendmail -t -i” to your php.ini, you must restart Apache AND php-fpm:

sudo /opt/bitnami/ctlscript.sh restart php-fpm

Simpy restarting Apache is not enough.

3 Likes

Correct, it is necessary to restart php-fpm to load the new option for PHP.

1 Like

I followed the instructions above but my send mail function is still not working, so I can’t use it to retrieve lost passwords from wordpress or anything that requires send mail.

Below are my settings and I even added mail function for using the smtp option and this didn’t work either, can you give me the correct code if I have entered anything wrong:

[mail function]
; For Win32 only.
; http://php.net/smtp
; SMTP = mail.domainnameremoved.com
; http://php.net/smtp-port
; smtp_port = 26
; auth_username = email@domainnameremoved.com
; auth_password = passwordremoved

; For Win32 only.
; http://php.net/sendmail-from
; sendmail_from = email@domainnameremoved.com
; auth_username = email@domainnameremoved.com
; auth_password = passwordremoved

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
; http://php.net/sendmail-path
;sendmail_path = “env -i /usr/sbin/sendmail -t -i”

I’ve restarted the server with sudo /opt/bitnami/ctlscript.sh restart php-fpm and when I try to password retrieve with wordpress I get the following message:

The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function.

Hi @Simeon_Tuitt

The correct code should be:

[mail function]
; For Win32 only.
; http://php.net/smtp; SMTP = mail.domainnameremoved.com
; http://php.net/smtp-port; smtp_port = 26
; auth_username = email@domainnameremoved.com
; auth_password = passwordremoved

; For Win32 only.
; http://php.net/sendmail-from; sendmail_from = email@domainnameremoved.com
; auth_username = email@domainnameremoved.com
; auth_password = passwordremoved

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "env -i /usr/sbin/sendmail -t -i"

Note that in front of sendmail_path there isn’t the “;”. Could you try again after modify your code?

Don’t forgot to restart php-fpm, please.

PS: I guess you are talking about GNU/Linux or MacOSX, right?

I made the changes but send mail still isnt working and neither is password retrieve on wordpress, even after restarting the server like instructed above. For some reason even php doesn’t function properly, is there a way to turn on full functionality of php on a bitnami instance. I just had script created Today and you put data in and click create and it should spew out custom html, but the create function isn’t working due to something with the php because the script works fine on my other non aws server.

Hi @Simeon_Tuitt,

Have you installed sendmail? It is not installed by default in the Bitnami AMIs. Please, execute

sudo apt-get install sendmail

And then try again. As @beltran said at the beginning of the post, you have to take into account the sendmail limits that Amazon has.
Hope it helps!

Thanks for the reply, I just did that and restarted server and tried password retrieve on wordpress again and still got the following message:

The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function.

Attached is an image of what it said when I ran the send mail instruction at command prompt.image

Hi @Simeon_Tuitt,

I cannot see the full image, just part of it. Could you send the good one to hello [at] bitnami [dot] com so that we can check it? Apart from that, it’s quite weird that you cannot use the sendmail tool. Could you check the apache error log (/opt/bitnami/apache2/logs/error_log) to see if we can find out the problem?

Regards

Hi @Simeon_Tuitt,

I’ve been checking the image you sent by mail. It is the same than here, I cannot see any error and I don’t know if you find any one. It is quite weird that it is not working on your side after installing sendmail. I tested it myself and it works. Could you tell us if there was any problem installing sendmail? Could you copy a snippet of the php.ini file where we can see the sendmail configuration? Could you check the apache error log and let us know what you find?

Best regards

I’m having the same problem.

If I activate the mail plugin its options doesn’t appear on the Network so I can’t change the network e-mail address.

If I add a user inside a site, the same problem.

And now my e-mail address is blocked and I can’t use it to keep trying.

So, can anybody please update the solution for this problem?

Also how can I remove the users I tried to add from the database so I can add them again, with an e-mail sent?

It is not straight forward as just deleting an entry in the phpmyadmin.

Hi @dpedrinha

This is the same issue, right?

Regards,
Fran

enter below command on terminal and check error.

echo "This is a test mail. Please do not reply" | mail -s Test Email receiver@site-name.domain
1 Like