我已经将XAMPP中的php.ini和sendmail.ini配置为发送电子邮件及其工作正常。现在,当我将php中的代码更改为使用SMTP时,它无法工作.它使用与XAMPP相同的主机、相同的smtpsecure、相同的端口、相同的电子邮件,而且它不能工作。
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=testowemailer93@gmail.com
auth_password=1234
force_sender=testowemailer93@gmail.com
php.ini
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = testowemailer93@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
For Win32 only.
http://php.net/sendmail-from
sendmail_from = testowemailer93@gmail.com
and my php code
<?php
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Port = 587;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'testowemailer93@gmail.com'; // SMTP username
$mail->Password = '1234'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->setLanguage('pl', './vendor/phpmailer/phpmailer/language/phpmailer.lang-pl.php');
$mail->setFrom("testowemailer93@gmail.com");
$mail->addAddress('xx.yyy@gmail.com'); // Add a recipient // Name is optional
$mail->IsHTML(true);
$mail->Subject = "Prośba o dostęp demo";
$mail->Body = "<p>Wysłano z formularza kontaktowego na stronie bhp.xyz.pl.</p>
</p>";
if(!$mail->Send()){
echo "\n"."Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message sent!";
}
?>
错误:服务器->客户端: 220 smtp.gmail.com ESMTP f40sm329317edb.7 - gsmtp客户端->服务器: EHLO PhpStorm 2017.1 SERVER -> CLIENT: 501-5.5.4 HELO/EHLO参数"PhpStorm 2017.1“无效,关闭连接。501 5.5.4 https://support.google.com/mail/?p=helo f40sm329317edb.7 - gsmtp SMTP错误: EHLO命令失败: 501-5.5.4 HELO/EHLO参数"PhpStorm 2017.1”无效,关闭连接。501 5.5.4 https://support.google.com/mail/?p=helo f40sm329317edb.7 - gsmtp客户端->服务器: HELO PhpStorm 2017.1服务器->客户端: SMTP错误: HELO命令失败: SMTP通知:->在检查是否连接SMTP错误:无法连接到SMTP主机时捕获。SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting邮件发送错误: SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
发布于 2017-05-26 01:53:50
我想出来了..。在这样的事情上花费了太多的时间。我在XAMPP中添加了虚拟主机:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "D:/xampp/htdocs/BHP"
ServerName bhpsmart.com
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
<Directory "D:/xampp/htdocs/BHP">
Options All
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog logs/platforma-error.log
LogLevel info
CustomLog logs/platforma.log combined
</VirtualHost>
它们的重点是:
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
现在它正常工作了。
发布于 2017-05-26 01:50:23
这实际上是PHPStorm中的一个bug,我报告了这里。
在PHPMailer 6.0分支中有一个自动的解决方法,但是您应该能够通过将Hostname
属性设置为有效的东西来实现它,例如:
$mail->Hostname = 'localhost.localdomain';
Hostname
属性是Host
属性中给服务器的HELO/EHLO命令中显示的名称--不要混淆这两个属性!
https://stackoverflow.com/questions/44198105
复制相似问题