如何在PHP-FPM中使用PHP Mail()函数?在Nginx上?

The*_*Kid 12 php email nginx

我到处寻找这个,我真的想解决这个问题.在过去,我最终使用的是像SendGrid for PHP这样的SMTP服务和一个像SwiftMailer这样的邮件插件.但是我想使用PHP.

基本上我的设置(我是服务器设置的新手,这是我的教程后的个人设置)

Nginx
Rackspace Cloud
PHP 5.3 PHP-FPM
Ubuntu 11.04
Run Code Online (Sandbox Code Playgroud)

phpinfo()将返回有关邮件条目的信息:

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
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我,因为为什么Mail()不起作用 - 我的脚本正在所有其他网站上工作,这是一个普通的邮件命令.我是否需要在服务器上设置日志或启用某些PHP端口?

我的示例脚本

<?
    # 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);

?>
Run Code Online (Sandbox Code Playgroud)

谢谢

Mit*_*ell 13

因为没有价值sendmail_from你需要设置一个php.ini:

sendmail_from = "you@example.com" 
Run Code Online (Sandbox Code Playgroud)

或者在您致电时在标题中mail:

mail($to, $subject, $message, 'From: you@example.com');
Run Code Online (Sandbox Code Playgroud)

电子邮件地址应遵循RFC 2822,例如:

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

如果做不到,你真的安装了一个有效的电子邮件系统吗?

如果没有,您可以使用以下命令安装postfix:

sudo apt-get install postfix

有关在Ubuntu中配置用于PHP的postfix的更多信息,请参阅下文:

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


The*_*son 13

如果在使用nginx和PHP-FPM(没有apache)的Ubuntu 14.04的新安装中发现,则既没有安装postfix也没有安装mailutils.

我用了: sudo apt-get install postfix

(如推荐的答案)

sudo apt-get install mailutils

让我的服务器上的一切工作.两者都是必需的.PHP.ini中的一个条目(如推荐答案中所述)也可能有所帮助,但如果没有其他两个软件包,它就不会产生任何影响.