使用phpmailer和gmail为什么它不起作用

时间:2016-05-17 04:02:49

标签: php html phpmailer

我正在使用phpmailer提交表单并将其发送到我的电子邮件,但它不会工作,我想出了为什么它不会工作。你们会为我看看它,并弄清楚它为什么不起作用?它给了我一个错误,说抱歉此时无法发送,这是我犯的错误。任何想法为什么它不起作用?

<?php

session_start();

require_once 'libs/PHPMailer/PHPMailerAutoload.php';

$errors = [];

if(isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['message'])) {
    $fields = [
    'name' => $_POST['name'],
    'email' => $_POST['email'],
    'subject' => $_POST['subject'],
    '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->HOST = 'smtp.gmail.com';
    $m->Username = 'contactdocketsolution@gmail.com';
    $m->Password = 'not showing password but it is valid';
    $m->SMTPSecure = 'ssl';
    $m->Port = 465;

    $m->isHTML();

    $m->Subject = '' . $fields['subject'] . 'Docket-Solutions COntact Form';
    $m->Body = 'From: ' . $fields['name'] . ' (' . $fields['email'] . ')<p>' . $fields['message'] . '</p>';

    $m->FromName = 'Docket-Solutions Customer';

    $m->AddAddress('support@docket-solutions.com', 'Bob');

    if($m->send()) {
        header('Location: index.html');
        die();
    }else{
        $errors[] = 'Sorry, could not send email. Try again later.';
    }


}

} else {
$errors[] = 'Something went wrong.';
}

$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('Location: contact.php');




?>

0 个答案:

没有答案