本文介绍了使用phpmailer从Gmail发送电子邮件。登录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法理解为什么我无法使用php中的各种邮件类发送电子邮件。我知道我的密码等是正确的。

I cant seem to get my head around why i cant send emails using all sorts of mail classes in php. I know my password etc is correct.

任何人有任何想法吗?

我收到错误消息:



function mail1($to,$body,$subject){

    include "/libs/mailer/classes/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->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->Username = "[email protected]";
    $mail->Password = "xxxxxxxx";
    $mail->SetFrom("[email protected]");
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);

    if(!$mail->Send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else{
        echo "Message has been sent";
    }

}


推荐答案

此链接始终可以帮助我解决从我的应用程序到gmail的任何登录问题。试试这个可能对您有帮助。

This link always help me for any kind of login problem into gmail from my application. Try this may it can helps you...

在这里,请尝试登录不太安全的应用程序:

Here, trun on logging for less secure apps: https://www.google.com/settings/u/1/security/lesssecureapps

在这里,只需单击继续...

Here, just click continue... https://accounts.google.com/b/0/DisplayUnlockCaptcha

并检查此处是否有任何日志记录到您的帐户:

And check here is there any logging to your account: https://security.google.com/settings/security/activity?hl=en&pli=1

然后,运行您的代码。

这篇关于使用phpmailer从Gmail发送电子邮件。登录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:26