【问题标题】:PHPMailer not running with Xampp on Windows10PHPMailer 未在 Windows10 上与 Xampp 一起运行
【发布时间】:2018-06-20 20:31:01
【问题描述】:

我的问题是当我使用 Xampp 和 Windows10 运行 PHPMailer(确切地说是 PHPMailer-master 6.0.3)时,它不会发送电子邮件。 (我发现了很多关于这个主题的 cmets,但没有一个能找到解决方案。)

以下代码在远程服务器上运行良好:

 <?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


// 'PHPMailer' here actually is the original folder 'PHPMailer-master' 
// from unpacking the downloaded file PHPMailer-master.zip
require 'vendor/PHPMailer/src/Exception.php';
require 'vendor/PHPMailer/src/PHPMailer.php';
require 'vendor/PHPMailer/src/SMTP.php';

echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n"; 

$mail = new PHPMailer(true);         // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;            // Enable verbose debug output

    $mail->$mail->isSendmail();     // corrected 
    $mail->Host = 'smtp.kabelmail.de';          //smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                 // Enable SMTP authentication
    $mail->Username = 'myname@kabelmail.de';     // SMTP username
    $mail->Password = 'mypassword';              // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                           // TCP port to connect to

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('myname@kabelmail.de', 'myname');  // Add a recipient
    // $mail->addAddress('ellen@example.com');           // Name is optional
    $mail->addReplyTo('myname@web.de', 'Antwort');
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    //Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');     // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                        // Set email format to HTML
    $mail->Subject = 'Here is the subject:localhost';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = ' body in plain text for non-HTML mail lients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>

我保留了上面的脚本,并根据Phpmailer not working running from localhost (XAMPP)的cmets为Xampp修改了php.ini:

[mail function]
SMTP=smtp.kabelmail.de
smtp_port=465
sendmail_from = to@kabelmail.de
sendmail_path ="C:\xampp\sendmail\sendmail.exe\"
;(I also tried sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" but without success.)
mail.log="C:\xampp\php\logs\php_mail.log"

这些是对 sendmail.ini 的修改:

[sendmail]
smtp_server=smtp.kabelmail.de
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=myname@kabelmail.de
auth_password=mypassword

结果: 1. 通过上面的设置,我收到了这条消息:

SSL loaded 2018-01-11 12:06:10 SERVER -> CLIENT: 421 4.3.2 Too many open connections.
2018-01-11 12:06:10 CLIENT -> SERVER: EHLO localhost
2018-01-11 12:06:10 SERVER -> CLIENT: 
2018-01-11 12:06:10 SMTP ERROR: EHLO command failed: 
2018-01-11 12:06:10 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.
  1. 然后我替换了 $mail->isSendmail();通过 $mail->isMail(); 现在出现的消息是 SSL 加载消息已发送

这正是我要找的,但是 - 邮箱里没有消息。!!! php_mail.log 有这个信息,这对我来说并不可疑:

    [11-Jan-2018 13:09:32 Europe/Berlin] mail() on [C:\xampp\htdocs\to\vendor\PHPMailer\src\PHPMailer.php:768]: To: "name" <myname@kabelmail.de> -- Headers: Date: Thu, 11 Jan 2018 13:09:32 +0100  From: Mailer <from@example.com>  Reply-To: Antwort <myname@web.de>  Message-ID: <VuAQ3BR022MQyNd3hKCoguqr50Ry9TPG4vIRL2ZmFg@localhost>  X-Mailer: PHPMailer 6.0.3 (https://github.com/PHPMailer/PHPMailer)  MIME-Version: 1.0  Content-Type: multipart/alternative;     boundary="b1_VuAQ3BR022MQyNd3hKCoguqr50Ry9TPG4vIRL2ZmFg"  Content-Transfer-Encoding: 8bit

谁能给我一个提示可能是什么问题? 我已经为此工作了几天,但显然我缺少一些基本的东西。

--- 2018 年 1 月 12 日编辑 -------------------------------------------------- ------------

$mail->isSendmail();是远程服务器上的设置没问题!

【问题讨论】:

    标签: xampp window phpmailer


    【解决方案1】:

    解决了。

    当我搬到 smtp.web.de 时,突破就达到了。

    我现在从客户端和服务器获取消息 ($mail->SMTPDebug = 2;)。

    服务器还在抱怨

    $mail->setFrom('from@example.com', 'Mailer');
    

    “MAIL FROM 命令失败:550 - 未采取请求的操作:邮箱不可用550 不允许发件人地址”。

    替换为

    $mail->setFrom('myname@web.de', 'via web.de');
    

    完成了这项工作。但并非所有服务器都抱怨这一点。例如 Dogado.de 就没有。

    最后:

    $mail->SMTPDebug = 0;     // suppresses server and client messages for production use
    $mail->CharSet = "UTF-8";  // for correct umlauts
    

    总结

    以下代码可以在本地机器(Xampp、Netbeans)以及远程服务器上使用。

    <?php
    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    
    // adjust path accordingly!
    require 'vendor/PHPMailer/src/Exception.php';
    require 'vendor/PHPMailer/src/PHPMailer.php';
    require 'vendor/PHPMailer/src/SMTP.php';
    
    
    // is ssl loaded? (test only):
    //echo (extension_loaded('openssl')?'SSL loaded, ':'SSL not loaded, ')."\n"; 
    
    $mail = new PHPMailer(true);             // Passing `true` enables exceptions
    try {
        $mail->SMTPDebug = 0;   // production use
        $mail->isSMTP();            // Set mailer to use SMTP
    
        //=== using web.de ========================================
        // adjust settings to your project!
        $mail->Host = 'smtp.web.de';             //smtp1.example.com;smtp2.example.com';  
                                                 // Specify main and backup SMTP servers
        $mail->Username = 'myname@web.de';       // SMTP username   
        $mail->Port = 587;                       // TCP port to connect to
        $mail->setFrom('myname@web.de', 'über web.de'); // required by web.de
        $mail->Password = 'mypassword';          // SMTP password
        //==========================================================
        $mail->SMTPAuth = true;                  // Enable SMTP authentication
        $mail->SMTPSecure = 'tls';          // Enable TLS encryption, `ssl` also accepted
    
        //Recipients
        $mail->addAddress('myname@kabelmail.de', 'my name'); // Add a recipient
        $mail->addAddress('myname@web.de');                // Name is optional
        $mail->CharSet = "UTF-8";               // because of umlauts
    
        //$mail->addCC('cc@example.com');
        //$mail->addBCC('bcc@example.com');
    
        //Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    
        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold! groß süß ähnlich Ökonom</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients: groß süß ähnlich Ökonom';
    
        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-11
      • 1970-01-01
      • 2015-03-31
      • 2016-03-08
      • 2013-12-05
      • 2014-02-16
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多