我有一个支持邮件的服务器,比如说example.com
。我配置了服务器并通过cpanel添加了MX记录,这样我就可以通过outlook.com
有地址[email protected] /cdn-cgi/l/email-protection
。 MX 记录来自domains.live.com
.
现在我需要使用 PHP 使用 SMTP 以编程方式发送邮件。我使用以下脚本尝试了 PHPmailer。但它显示错误
Mailer Error: SMTP Connect() failed.
(但我可以使用 Outlook.com 发送和接收电子邮件[电子邮件受保护] /cdn-cgi/l/email-protection)
$body = $_POST['message'];
$to = "[email protected] /cdn-cgi/l/email-protection";
$from = '[email protected] /cdn-cgi/l/email-protection';
$fName = 'first name';
$lName = 'last name';
$subject = 'my subject';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
// $body = eregi_replace("[\]",'',$body);
$mail->Host = "mail.example.org"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected] /cdn-cgi/l/email-protection"; // SMTP account username example
$mail->Password = "password";
$mail->SetFrom($from, $fName.' '.$lName);
$mail->Subject = $subject;
$mail->AddAddress($to, "Support Team");
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
我该如何解决这个问题。
最后,我通过替换下面的一些设置解决了这个问题,它成功了:)。
$mail->Host = "smtp-mail.outlook.com"; // SMTP server example
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)