简体   繁体   English

php pear电子邮件可与gmail smtp一起使用,但不会通过本地服务器发送电子邮件

[英]php pear email works with gmail smtp, but no emails get sent with local server

I just upgraded to ubuntu 12.04, installed pear, mail and mail_mime. 我刚刚升级到ubuntu 12.04,安装了pear,mail和mail_mime。 I am using a sample code below. 我在下面使用示例代码。 It used to work, but I am not sure If I had some changes made in php.ini. 它曾经可以工作,但是我不确定是否在php.ini中进行了一些更改。 It has been sometime since my last setup. 自上次设置以来已经有一段时间了。 I tested with gmail smtp server, and all works good. 我使用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);
?>

Is there something I am missing? 我有什么想念的吗? Should I change sendmail_path in php.ini? 我应该在php.ini中更改sendmail_path吗? or something? 或者其他的东西?

You can find your errors of that from the error.log file of apache check 您可以从apache check的error.log文件中找到该错误

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

here you can find your error of sending mails 在这里您可以找到发送邮件的错误

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

any try to send mail now :) 任何尝试立即发送邮件:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM