PHPMailer在Windows10上没有运行Xampp

时间:2018-01-11 13:30:49

标签: xampp window phpmailer

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

以下代码在远程服务器上运行正常:

 <?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)的注释修改了php.ini for Xampp:

[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-&gt; isSendmail();通过$ mail-&gt; isMail(); 现在出现的信息是 已加密SSL已发送消息
  2. 这就是我要找的东西,但是 - 邮箱里没有留言。!!! 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-&GT; isSendmail();是远程服务器上正常的设置!

1 个答案:

答案 0 :(得分:0)

解决。

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

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

服务器仍抱怨

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

&#34; MAIL FROM命令失败:550-未执行请求的操作:邮箱不可用550不允许发件人地址&#34;。

取代
$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;
}