13

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

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

Nginx
Rackspace Cloud
PHP 5.3 PHP-FPM
Ubuntu 11.04

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

有人可以帮我解释为什么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);

?>

谢谢

4

2 回答 2

15

如果发现在带有 nginx 和 PHP-FPM(没有 apache)的 Ubuntu 14.04 的新安装中,postfix 和 mailutils 都没有安装。

我用了: sudo apt-get install postfix

(如推荐的答案)

sudo apt-get install mailutils

让一切都在我的服务器上运行。两者都是必需的。PHP.ini 中的条目(如推荐的答案中所述)可能也有帮助,但如果没有其他两个包,它不会有什么不同。

于 2014-09-15T16:08:36.870 回答
14

由于没有任何价值,sendmail_from您需要在以下位置设置一个php.ini

sendmail_from = "you@example.com" 

或者当您调用时在标题中mail

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

电子邮件地址应遵循 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

于 2012-11-02T10:32:13.913 回答