通过phpmailer连接到Gmail

通过phpmailer连接到Gmail,php,email,authentication,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['t

我正在尝试连接到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";
    }
}
?>

当我尝试运行此代码时,我发现以下错误: 如何修复它

$mail->Host        = 'smtp.gmail.com';
$mail->Port        = 587;
$mail->SMTPSecure  = 'tls';
$mail->SMTPAuth    = true;
$mail->Username    = "user@gmail.com";
$mail->Password    = "pass";

问候语

你读到错误了吗?您的用户名/密码不正确。它甚至会告诉你一个url来获取答案……不,你没有,或者你已经在错误中找到了url,并学会了该怎么做:
Learn more at 534 5.7.14https://support.google.com/mail/answer/78754
仅仅因为您的密码可以在家用计算机上使用并不意味着它可以在服务器所在的任何位置使用。