通过phpmailer连接到Gmail

时间:2015-07-30 21:55:40

标签: php email authentication

我尝试连接到位于gmail.com的电子邮件。我想创建联系表格。我在HTML中创建了表单联系人。现在我尝试使用phpmailer类进行连接。我展示了我的代码:

<?php
$name = isset($_POST['name']) ? $_POST['name'] : false;
$email = isset($_POST['email']) ? $_POST['email'] : false;
$topic = isset($_POST['topic']) ? $_POST['topic'] : false;
$message = isset($_POST['message']) ? $_POST['message'] : false;

error_reporting(E_ALL);
ini_set("display_errors", 1);

if(isset($_POST['send_message'])){
    include "../phpmailer/class.phpmailer.php"; // include the class name
    $mail = new PHPMailer(); // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPKeepAlive = true;
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->Username = "myemail@gmail.com";
    $mail->Password = "mypassword";
    $mail->SetFrom("myemail@gmail.com");
    $mail->AddAddress('myemail@gmail.com','MyName');
    $mail->Subject = "Here is the subject";
    $mail->Body = "This is the HTML message body <b>in bold!</b>";
     if(!$mail->Send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else{
        echo "Message has been sent";
    }
}
?>

当我尝试运行此代码时,我会发现以下错误: http://pastebin.com/R7PBZDei 如何解决?

1 个答案:

答案 0 :(得分:1)

z1

问候