我知道之前已经问过这个问题,并且我已经实施了所有可以找到但没有成功的建议。 在我放弃PHPmailer并使用神秘的PHP邮件之前,我认为可能在某个地方可能有一个解决方案。
PHP
<?php
require_once 'class.phpmailer.php';
function sendEmail($subject, $body, $toEmail, $fromEmail, $fromName = 'N/A', $isHTML=false, $msg="Thank you for contacting us. Your message has been sent.")
{
try
{
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->Host = 'mail.privateemail.com';
$mail->Port = '465';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'admin@writers-tryst.com'; // SMTP username
$mail->Password = 'MYPWD';
$mail->SMTPSecure = "ssl";
$mail->From = $fromEmail;
$mail->FromName = $fromName;
$mail->Subject = $subject;
if ($isHTML) $mail->IsHTML(true);
$mail->Body = $body;
$mail->AddAddress($toEmail);
$result = $mail->Send() ? 1 : 0;
if (count($msg)) echo $msg;
return $result;
} catch (phpmailerException $e) {
return $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
return $e->getMessage(); //Boring error messages from anything else!
}
}
?>
答案 0 :(得分:0)
尝试添加:
$mail->SMTPDebug = 2
仅用于调试和获取有关连接的更多信息。 并添加:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
此代码可帮助您获得更安全的连接。