安装openssl后出现PEAR :: Mail错误

时间:2018-02-05 21:34:40

标签: php email

我今天一直在我的服务器上安装ssl(debian),有效! 但除此之外发生了一些变化,现在我无法发送电子邮件。 这在以前从来就不是问题。

出现此错误:

authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 SMTP server ready)]

我的代码:

function sendemail($too, $title, $post){
set_include_path("." . PATH_SEPARATOR . ($UserDir = dirname($_SERVER['DOCUMENT_ROOT'])) . "/pear/php" . PATH_SEPARATOR . get_include_path());
require_once "Mail.php";

$host = "smtp-mail.outlook.com";
$username = "no-reply@developerhelp.org";
$password = "****";
$port = "587";
$to = $too;
$email_from = 'DeveloperHelp <no-reply@developerhelp.org>';
$email_subject = "DeveloperHelp: ".$title;
$email_body = $post;
$email_address = "";

$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);


if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
}
}

先谢谢!

1 个答案:

答案 0 :(得分:0)

我通过使用PHPmailer修复了问题并允许自签名证书。将这些行添加到PHPMailer:

$mail->SMTPOptions = array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                    )
                );