如何在 PHP-FPM 中使用 PHP Mail() 函数?在 Nginx 上?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13193433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use PHP Mail() function within PHP-FPM? On Nginx?
提问by TheBlackBenzKid
I have searched everywhere for this and I reallywant to resolve this. In the past I just end up using an SMTP service like SendGrid for PHP and a mailing plugin like SwiftMailer. However I want to use PHP.
我到处搜索这个,我真的很想解决这个问题。过去,我只是使用了像 PHP 的 SendGrid 这样的 SMTP 服务和像 SwiftMailer 这样的邮件插件。但是我想使用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.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. Do I need to setup logs or enable some PHP port on the server?
有人可以帮助我解释为什么Mail()不起作用 - 我的脚本正在所有其他站点上运行,它是一个普通的邮件命令。我是否需要在服务器上设置日志或启用某些 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: <[email protected]>' . "\r\n";
// SEND MAIL
mail($to,$subject,$message,$headers);
?>
Thanks
谢谢
回答by TheDavidJohnson
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
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 中的条目(如推荐答案中所述)也可能有所帮助,但如果没有其他两个包,它不会有什么不同。
回答by Mitch Satchwell
As there is no value for sendmail_fromyou need to set one in php.ini:
由于没有价值,sendmail_from您需要在 中设置一个php.ini:
sendmail_from = "[email protected]"
Or in the headers when you call to mail:
或者在您致电时的标题中mail:
mail($to, $subject, $message, 'From: [email protected]');
The email address should follow RFC 2822 for example:
例如,电子邮件地址应遵循 RFC 2822:
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
sudo apt-get install postfix
See below for more information on configuring postfix for use with PHP in Ubuntu:
有关配置 postfix 以在 Ubuntu 中与 PHP 一起使用的更多信息,请参见下文:
https://serverfault.com/questions/119105/setup-ubuntu-server-to-send-mail
https://serverfault.com/questions/119105/setup-ubuntu-server-to-send-mail

