PHPMailer邮件未发送=>许多错误

时间:2016-05-20 14:49:17

标签: php email smtp phpmailer

我想使用PHPMailer使用Mail功能,以便为填写表单的人发送电子邮件确认。

这是我的发送邮件代码=>

 /* some codes with already a phpmyadmin database and a form */


function send_mail($email,$message,$subject) // method called, ignore the param
    {                       
        require_once('mailer/class.phpmailer.php');
    $mail = new PHPMailer();

    $mail->IsSMTP();
    $mail->SMTPDebug = 2;
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';

    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; // for ssl
    $mail->Username = 'an_email_test_1@gmail.com';
    $mail->Password = 'pwd_of_username_just_above';

    $mail->SetFrom('an_email_test_1@gmail.com'); // same as ->Username
    $mail->Subject = "Test Mail";
    $mail->Body = "Hi.";
    $mail->AddAddress('an_email_test_2@gmail.com');

    if (!$mail->Send())
        return 'Mail error:' . $mail->ErrorInfo;
    return 'Success, check your mail.';
}

我收到了“未找到SMTP类”,所以我在 require_once('mailer / class.phpmailer.php')正下方 =>

        require 'mailer/PHPMailerAutoload.php';

并且感谢启用了SMTPDebug,它给了我这个错误>

2016-05-20 14:27:49 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:49 CLIENT -> SERVER: EHLO "name_of_my_virtualhost" (I use WAMP3.0.4)
2016-05-20 14:27:49 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [80.215.180.91] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 
2016-05-20 14:27:49 CLIENT -> SERVER: AUTH LOGIN 
2016-05-20 14:27:49 SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2016-05-20 14:27:49 CLIENT -> SERVER: bG9nYW4ucGV5cnkxQGdtYWlsLmNvbQ== 2016-05-20 14:27:49 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2016-05-20 14:27:49 CLIENT -> SERVER: Y29jaG9uOTM= 
2016-05-20 14:27:50 SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:50 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:50 SMTP Error: Could not authenticate. 
2016-05-20 14:27:50 CLIENT -> SERVER: QUIT 
2016-05-20 14:27:50 SERVER -> CLIENT: 221 2.0.0 closing connection h4sm20018967wjz.20 - gsmtp 
2016-05-20 14:27:50 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

我真的不知道如何解决它,我只是想发送一个简单的邮件,目前没有任何信息,特别为此创建了2个gmail地址。 n°1为发件人,n°2为收件人

我应该从邮件功能中的apache php.ini或其他内容更改某些内容吗? 谢谢你帮助我:)。

1 个答案:

答案 0 :(得分:0)

您是否已激活PHP中的php_openssl扩展程序

使用菜单

wampmanager -> PHP -> PHP Extension -> php_openssl

如果此菜单项旁边没有TICK,请单击php_openssl菜单行,它将激活扩展并为您重新启动Apache,以便查看更改。

您可能还需要Allow less secure password帐户