php pear email适用于gmail smtp,但没有电子邮件与本地服务器一起发送

时间:2012-11-23 04:52:16

标签: php email pear

我刚刚升级到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吗?还是什么?

1 个答案:

答案 0 :(得分: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

现在尝试发送邮件:)