使用IIS 7和PHP7.1 我设法将我的服务器连接到我们的SMTP服务器(在不同的IP地址上) 我通过安静简单地编辑我的php.ini文件
来做到这一点SMTP = mail.<Domain>.co.uk
smtp_port = 25
sendmail_from = mail@<Domain>.co.uk
通过调用php脚本,发送了一封电子邮件
<?php
$msg = "Hello Do I Work Im From the Server";
mail("joe@<Domain>.co.uk","My subject",$msg);
?>
这可以使电子邮件收件人位于同一个域中。
然而,要求将电子邮件发送给任何人。当我尝试这个时,使用上面的代码和设置我得到了这个错误
PHP Warning: mail(): SMTP server response: 550 5.7.1 Unable to relay in …
快速阅读后我发现PHP 7.1不允许使用smtp密码,而这些密码缺少导致上述错误。我需要一个外部邮件库 1)这是正确的
我下载并安装了phpmailer(如果需要,我可以更改)并运行以下脚本
<?php
require_once "PHPMailerAutoload.php";
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = "mail.<Domain>.co.uk";
$mail->SMTPAuth = true;
$mail->Username = "mail@<Domain>.co.uk";
$mail->Password = "<Password>";
$mail->SMTPSecure = "tls";
$mail->Port = 25;
$mail->From = "mail@<Domain>.co.uk";
$mail->FromName = "Mail";
$mail->addAddress("joe@<Domain>.co.uk");
$mail->addReplyTo("mail@<Domain>.co.uk", "Reply");
$mail->isHTML(true);
$mail->Subject = "Test";
$mail->Body = "From the Server";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
我跑了这个并得到了错误
2017-05-19 11:57:52 Extension missing: openssl Mailer Error: Extension missing: openssl
所以我在php.ini
中取消注释extension=php_openssl.dll
重新编写脚本并获得
2017-05-19 11:59:14 Connection: opening to mail.<Domain>.co.uk:25, timeout=300, options=array ( ) 2017-05-19 11:59:14 Connection: opened 2017-05-19 11:59:14
SERVER -> CLIENT: 220 PATHEX01.pathways.local Microsoft ESMTP MAIL Service ready at Fri, 19 May 2017 12:59:14 +0100 2017-05-19 11:59:14
CLIENT -> SERVER: EHLO www.<Domain>.co.uk 2017-05-19 11:59:14
SERVER -> CLIENT: 250-PATHEX01.pathways.local Hello [146.255.105.211] 250-SIZE 37748736 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-X-ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 XRDST 2017-05-19 11:59:14
CLIENT -> SERVER: STARTTLS 2017-05-19 11:59:14
SERVER -> CLIENT: 220 2.0.0 SMTP server ready 2017-05-19 11:59:15 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [C:\inetpub\wwwroot\EmailTest\class.smtp.php line 369] 2017-05-19 11:59:15 SMTP Error: Could not connect to SMTP host. 2017-05-19 11:59:15
CLIENT -> SERVER: QUIT 2017-05-19 11:59:15
SERVER -> CLIENT: 2017-05-19 11:59:15 SMTP ERROR: QUIT command failed: 2017-05-19 11:59:15 Connection: closed 2017-05-19 11:59:15 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
任何人都可以建议我做错了什么吗?感谢