我正在运行一个发送邮件的脚本,但我无法让它工作。
这是我的代码。有什么观察吗?:
<?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;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.serviciodecorreo.es'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'admin@*****.**'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('admin@*****.**');
$mail->addAddress('******@**.com'); // Add a recipient
//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!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
我已将调试更改为值 3,这就是我得到的。有谁知道会发生什么?
2018-02-23 09:05:56 Connection: opening to
ssl://smtp.serviciodecorreo.es:465, timeout=300, options=array()
2018-02-23 09:05:56 Connection failed. Error #2: stream_socket_client(): SSL
operation failed with code 1. OpenSSL Error messages:error:14090086:SSL
routines:ssl3_get_server_certificate:certificate verify failed
[C:\inetpub\SIADE\PHPMAIL\vendor\phpmailer\phpmailer\src\SMTP.php line 325]
2018-02-23 09:05:56 Connection failed. Error #2: stream_socket_client():
Failed to enable crypto
[C:\inetpub\SIADE\PHPMAIL\vendor\phpmailer\phpmailer\src\SMTP.php line 325]
2018-02-23 09:05:56 Connection failed. Error #2: stream_socket_client():
unable to connect to ssl://smtp.serviciodecorreo.es:465 (Unknown error)
[C:\inetpub\SIADE\PHPMAIL\vendor\phpmailer\phpmailer\src\SMTP.php line 325]
2018-02-23 09:05:56 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent. Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
它与IIS配置有关吗?
PHP 5.6 引入了 SSL 证书验证。它与 Web 服务器的 SSL 证书相同:它必须与域匹配,必须由受信任的 CA 签名,并且必须具有 SHA2 哈希和 2048 位密钥。如果您不想重新配置您的服务器,可以强制您的脚本恢复到检查证书之前的行为,即告诉它不要检查证书。这样,您将不再因证书不正确而出错