0

我刚刚升级到 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 吗?或者其他的东西?

4

1 回答 1

1

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

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

现在尝试发送邮件:)

于 2012-11-23T06:12:33.463 回答