PHPMailer在Windows10上没有运行Xampp
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHPMailer在Windows10上没有运行Xampp相关的知识,希望对你有一定的参考价值。
我的问题是,当我使用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 PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
// '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')."
";
$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:xamppsendmailsendmail.exe"
;(I also tried sendmail_path = ""C:xamppsendmailsendmail.exe" -t" but without success.)
mail.log="C:xamppphplogsphp_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.
- 然后我更换了$ mail-> isSendmail();通过$ mail-> isMail();现在显示的消息是SSL已加载消息已发送
这就是我要找的东西,但是 - 邮箱里没有留言。!!! php_mail.log有这个信息,对我来说看起来并不可疑:
[11-Jan-2018 13:09:32 Europe/Berlin] mail() on [C:xampphtdocs ovendorPHPMailersrcPHPMailer.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();是远程服务器上的设置!
解决了。
当我搬到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 PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
// 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, ')."
";
$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;
}
以上是关于PHPMailer在Windows10上没有运行Xampp的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Windows 上对 PHPMailer/OpenSSL TLS SMTP 进行故障排除?
PHPMailer GoDaddy 服务器 SMTP 连接被拒绝