简体   繁体   English

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

[英]How can I use PHP Mail() function within PHP-FPM? On Nginx?

I have searched everywhere for this and I really want to resolve this. 我到处寻找这个,我真的想解决这个问题。 In the past I just end up using an SMTP service like SendGrid for PHP and a mailing plugin like SwiftMailer. 在过去,我最终使用的是像SendGrid for PHP这样的SMTP服务和一个像SwiftMailer这样的邮件插件。 However I want to use PHP. 但是我想使用PHP。

Basically my setup (I am new to server setup, and this is my personal setup following a tutorial ) 基本上我的设置(我是服务器设置的新手,这是我的教程后的个人设置)

Nginx
Rackspace Cloud
PHP 5.3 PHP-FPM
Ubuntu 11.04

My phpinfo() returns this about the Mail entries: 我的phpinfo()返回有关Mail条目的信息:

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 to as why Mail() will not work - my script is working on all other sites, it is a normal mail command. 有人可以帮助我解决为什么Mail()无法工作 - 我的脚本正在所有其他网站上工作,这是一个普通的邮件命令。 Do I need to setup logs or enable some PHP port on the server? 我是否需要在服务器上设置日志或启用某些PHP端口?

My Sample 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 谢谢

As there is no value for sendmail_from you need to set one in php.ini : 由于sendmail_from没有值,你需要在php.ini设置一个:

sendmail_from = "you@example.com" 

Or in the headers when you call to mail : 或者在您致电mail时在标题中:

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

The email address should follow RFC 2822 for example: 电子邮件地址应遵循RFC 2822,例如:

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

Failing that, have you actually installed a working email system? 如果做不到,你真的安装了一个有效的电子邮件系统吗?

If not, you can install postfix with the following command: 如果没有,您可以使用以下命令安装postfix:

sudo apt-get install postfix

See below for more information on configuring postfix for use with PHP in Ubuntu: 有关在Ubuntu中配置用于PHP的postfix的更多信息,请参阅下文:

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

If found that on a new installation of Ubuntu 14.04 with nginx and PHP-FPM (no apache), neither postfix nor mailutils were installed. 如果在使用nginx和PHP-FPM(没有apache)的Ubuntu 14.04的新安装中发现,则既没有安装postfix也没有安装mailutils。

I used: sudo apt-get install postfix 我用过: sudo apt-get install postfix

(as in the recommended answer) (如推荐的答案)

AND

sudo apt-get install mailutils

to get everything working on my server. 让我的服务器上的一切工作。 Both were required. 两者都是必需的。 An entry in PHP.ini (as mentioned in the recommended answer) may also have helped, but without both of the other packages, it wouldn't have made a difference. PHP.ini中的一个条目(如推荐答案中所述)也可能有所帮助,但如果没有其他两个软件包,它就不会产生任何影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM