PHPmailer:使用SMTP Hotmail的服务器500错误

时间:2015-12-15 14:20:12

标签: php email smtp phpmailer hotmail

当我尝试上传我的网站时,我一直收到服务器500错误。

我正在尝试使用PHPMailer设置PHP电子邮件联系表单。当我尝试连接我的本地主机时,我只是得到'抱歉,无法发送电子邮件。稍后再试一次'错误。

以下是代码:

<?php

session_start();

require_once '../phpmailer/PHPMailerAutoload.php';

$errors = [];

if(isset($_POST['name'], $_POST['email'], $_POST['message'])){

$fields = [

   'name' => $_POST['name'],
   'email' => $_POST['email'],
   'message' => $_POST['message']   

];

foreach($fields as $field => $data){
    if(empty($data)){
        $errors[] = 'The '. $field . ' field is required.';

    }
}

if(empty($errors)){

    $m = new PHPMailer;

    $m->isSMTP();
    $m->SMTPAuth = true;

    $m->SMTPDebug = 2;
    $m->Debugoutput = 'html';
    error_reporting(-1);

    $m->Host = 'smtp.live.com';
    $m->Username = 'email@hotmail.com';
    $m->Password = 'password';
    $m->SMTPSecure = 'tls';
    $m->Port = 587;

    $m->isHTML();

    $m->Subject = 'Website';
    $m->Body = 'From: ' . $fields['name'] . ' (' . $fields['email'] . ')<p>'     . $fields['message'] . '</p>';

    $m->FromName = 'Website Contact';
    $m->AddReplyTo($fields['email'], $fields['name']);

    $m->AddAddress('*********', '****');

    if($m->send()){

        header('Location: ../htdocs/index.php');
        die();

    } else {

        $errors[] = 'Sorry, could not send email. Try again later.';

    }

  }

} else {

$errors[] = 'Something went wrong.';

}

$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;

header('Location: ../htdocs/index.php');

?>

0 个答案:

没有答案