首页 文章

SMTP错误:无法进行身份验证 . PHPMailer的

提问于
浏览
0

我试图使用phpmailer发送邮件,但我发现错误,我的用户名和密码是完美的,而且密码不包含任何特殊字符 . 错误显示:SMTP错误:无法进行身份验证 . PHPMailer的

//------------------------- Mail to company section -----------------
$to='realbantimadrid@gmail.com';

$sender=$_POST['guest_name'];
$mail_id=$_POST['guest_mail'];
$cont_no=$_POST['guest_cont'];
$company=$_POST['guest_comp'];
$msg_txt=$_POST['guest_msg'];

if($sender== '' || $mail_id== '' || $cont_no== '' || $company== '' || $msg_txt== ''){
        echo "check the fields";
    }else{


    $subject='Query from '.$sender;
    $message='Dear Sir,<br><br>'.$msg_txt.'<br><br>From: '.$sender.'<br>Contact: '.$cont_no.'<br>Company Name: '.$company;


//---------------------------------- SMTP Authenticated Mail coding --------------------------
include "smtpmail/library.php"; // include the library file
include "smtpmail/classes/class.phpmailer.php"; // include the class name

    $email = $to;
    $mail  = new PHPMailer; // call the class 
    $mail->IsSMTP(); 
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com"; //Hostname of the mail server
    $mail->Port = 465; //Port of the SMTP like to be 25, 80, 465 or 587
    $mail->Username = "mailid@gmail.com"; //Username for SMTP authentication any valid email created in your domain
    $mail->Password = "password"; //Password for SMTP authentication
    $mail->AddReplyTo($mail_id, $sender); //reply-to address
    $mail->SetFrom($email, $sender); //From address of the mail
    // put your while loop here like below,
    $mail->Subject = $subject; //Subject of your mail
    $mail->AddAddress($email, "NYCLD Test Mailer"); //To address who will receive this email
    $mail->MsgHTML($message); //Put your body of the message you can place html code here
//  $mail->AddAttachment("images/asif18-logo.png"); //Attach a file here if any or comment this line, 
    $send = $mail->Send(); //Send the mails

    if($send)
        {
        echo "Thank you for your Feedback";
    }

    }

//------------------------ End of SMTP mail code ---------------------------------------



//--------------------------------------------------------------------


//------------------------- Mail to sender Section -----------------
$to=$mail_id;

$subject='Acknowledgement of Query from '.$sender;
$message='Dear '.$sender.',<br><br>Thank you for your feedback/query. Your mail has been delivered to concerned department. You will be contacted soon reagrding your query.<br><br>Regards,<br><br>Test Department';

//---------------------------------- SMTP Authenticated Mail coding --------------------------
include "smtpmail/library.php"; // include the library file
include "smtpmail/classes/class.phpmailer.php"; // include the class name

    $email = $to;
    $mail  = new PHPMailer; // call the class 
    $mail->IsSMTP(); 
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com"; //Hostname of the mail server
    $mail->Port = 465; //Port of the SMTP like to be 25, 80, 465 or 587
    $mail->Username = "mailid@gmail.com"; //Username for SMTP authentication any valid email created in your domain
    $mail->Password = "password"; //Password for SMTP authentication
    $mail->AddReplyTo($mail_id, "Fitwell India"); //reply-to address
    $mail->SetFrom($email, "Fitwell India"); //From address of the mail
    // put your while loop here like below,
    $mail->Subject = $subject; //Subject of your mail
    $mail->AddAddress($mail_id, $sender); //To address who will receive this email
    $mail->MsgHTML($message); //Put your body of the message you can place html code here
//  $mail->AddAttachment("images/asif18-logo.png"); //Attach a file here if any or comment this line, 
    $send = $mail->Send(); //Send the mails

//------------------------ End of SMTP mail code ---------------------------------------

1 回答

  • 1

    尝试更改 $mail->SMTPSecure = "tls"; 并使用 $mail->Port = 587; 也不要忘记启用从外部应用程序访问您的Gmail帐户,您应该收到有关访问尝试的Gmail帐户的电子邮件邀请 .

相关问题