How can I use the PHP Mail () function in PHP-FPM? On nginx?

I have searched everywhere for this, and I really want to solve it. I used to just use an SMTP service like SendGrid for PHP and a mailing plugin like SwiftMailer. However, I want to use PHP.

Basically my setup (I'm new to server setup, and this is my personal setup after the tutorial )

Nginx Rackspace Cloud PHP 5.3 PHP-FPM Ubuntu 11.04 

My phpinfo() returns this about mail records:

 mail.log no value mail.add_x_header On mail.force_extra_parameters no value sendmail_from no value sendmail_path /usr/sbin/sendmail -t -i SMTP localhost smtp_port 25 

Can someone help me because Mail() will not work - my script works on all other sites, this is a regular mail command. Do I need to configure logs or allow some PHP ports on the server?

My example script

 <? # FORMS VARS // $to = $customers_email; // $to = $customers_email; $to = $_GET["customerEmailFromForm"]; $subject = "Thank you for contacting Real-Domain.com"; $message = " <html> <head> </head> <body> Thanks, your message was sent and our team will be in touch shortly. <img src='http://cdn.com/emails/thank_you.jpg' /> </body> </html> "; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: < real-email@real-domain.com >' . "\r\n"; // SEND MAIL mail($to,$subject,$message,$headers); ?> 

thanks

+7
source share
2 answers

Since there is no value for sendmail_from , you need to set it in php.ini :

 sendmail_from = " you@example.com " 

Or in the headers when you call mail :

 mail($to, $subject, $message, 'From: you@example.com '); 

The email address must comply with RFC 2822, for example:

  • you@example.com
  • You < you@example.com >

Otherwise, did you actually set up a working email system?

If not, you can install postfix with the following command:

sudo apt-get install postfix

See below for more information on setting up a postfix for use with PHP in Ubuntu:

https://serverfault.com/questions/119105/setup-ubuntu-server-to-send-mail

+12
source

If it is discovered that during a new installation of Ubuntu 14.04 with nginx and PHP-FPM (without apache), neither postfix nor mailutils were installed.

I used: sudo apt-get install postfix

(as in the recommended answer)

and

sudo apt-get install mailutils

so that everything works on my server. Both were necessary. Writing in PHP.ini (as mentioned in the recommended answer) could also help, but without both the other packages, that would not have worked.

+9
source

All Articles