对不起,如果这是一条走路的路.我已经看到了关于这个的其他帖子,但他们中的任何一个都没有解决我遇到的问题或点燃了一个帮我自己解决的灯泡.
原文链接:https://www.f2er.com/php/137261.html这是我的代码:
require 'PHPMailerAutoload.PHP'; $config = parse_ini_file('/path/to/file/config.ini',true); $mail = new PHPMailer; $mail->SMTPDebug = 3; $mail->Debugoutput = 'html'; $mail->isSMTP(); $mail->Host = $config['host']; //smtp.office365.com $mail->SMTPAuth = true; $mail->Username = $config['username']; //an.existing.account@appinc.co $mail->Password = $config['password']; //confirmed this is being passed correctly $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->From = $config['username']; $mail->FromName = 'Website Forms'; $mail->addAddress('sales@appinc.co','Some Name'); $mail->addReplyTo('sender.email@somedomain.com','SenderFirst SenderLast'); $mail->addBCC('my.email.address@appinc.co'); $mail->isHTML(true); $mail->Subject = 'Contact Form Submission'; $mail->Body = 'Some html here'; $mail->AltBody = 'Some alt content here'; if(!$mail->send()) { echo 'Mailer Error: ' . $mail->ErrorInfo; } else { //perform success actions exit(); }
我已经确认域名,用户名和密码都是正确的并正确传递.需要注意的是,这在启动之前在我们的本地开发服务器上有效.一旦网站被移动到我们的托管帐户(Hostgator),它就会停止工作.我已经向HG确认我们的服务器上已打开587端口.
这是我看到的错误消息:
Connection: opening to smtp.office365.com:587,t=10,opt=array () SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP connect() Failed. Message could not be sent.Mailer Error: SMTP connect() Failed.