【问题标题】:php pear email works with gmail smtp, but no emails get sent with local serverphp pear email 可与 gmail smtp 一起使用,但本地服务器不会发送电子邮件
【发布时间】:2012-11-11 11:26:22
【问题描述】:

我刚刚升级到 ubuntu 12.04,安装了 pear、mail 和 mail_mime。我正在使用下面的示例代码。它曾经可以工作,但我不确定是否在 php.ini 中进行了一些更改。自从我上次设置以来已经有一段时间了。我用gmail smtp服务器测试过,一切正常。

<?
        include('Mail.php');
        include('Mail/mime.php');

        // Constructing the email
        $sender = "Leigh <leigh@no_spam.net>";                              // Your name and email address
        $recipient = "Leigh <leigh@no_spam.net>";                           // The Recipients name and email address
        $subject = "Test Email";                                            // Subject for the email
        $text = 'This is a text message.';                                  // Text version of the email
        $html = '<html><body><p>This is a html message</p></body></html>';  // HTML version of the email
        $crlf = "\n";
        $headers = array(
                        'From'          => $sender,
                        'Return-Path'   => $sender,
                        'Subject'       => $subject
                        );

        // Creating the Mime message
        $mime = new Mail_mime($crlf);

        // Setting the body of the email
        $mime->setTXTBody($text);
        $mime->setHTMLBody($html);

        $body = $mime->get();
        $headers = $mime->headers($headers);

        // Sending the email
        $mail =& Mail::factory('mail');
        $mail->send($recipient, $headers, $body);
?>

我有什么遗漏吗?我应该更改 php.ini 中的 sendmail_path 吗?还是什么?

【问题讨论】:

  • 你能用你的设置发送电子邮件吗?打开终端并输入:mail your@emailaddre.ss [enter] test [enter] test [enter] [enter] ctrl+d 并查看您的电子邮件。
  • @John 我试过了,但它说没有安装 mailutils。但即使在尝试安装它之前,我也了解到 php 没有默认的 sendmail,我必须安装它。我安装了它,现在它发送邮件(不过需要将近 10-15 秒)

标签: php email pear


【解决方案1】:

您可以从 error.log 文件中找到您的错误 的 apache 检查

sudo tail -f /var/log/apapche2/error.log

在这里你可以找到你发送邮件的错误

sudo apt-get install php-pear

sudo pear install mail

sudo pear install Net_SMTP

sudo pear install Auth_SASL

sudo pear install mail_mime

任何尝试现在发送邮件:)

【讨论】:

  • 感谢您的回复。错误日志中没有任何内容。我已经安装了除 Auth_SASL 之外的所有东西,但没有工作。之后我安装了 sendmail,现在它发送邮件但非常慢。知道为什么需要这么长时间吗?在我之前的安装中,它曾经运行良好
猜你喜欢
  • 2012-05-29
  • 2016-09-07
  • 2010-10-17
  • 2020-11-19
相关资源
最近更新 更多