2015-11-18 4 views
0

Я пытаюсь отправить почту с помощью phpmailer, но я обнаружил, что ошибка, Мое имя пользователя и пароль прекрасны, а также пароль не содержит специального символа. Ошибка: SMTP Ошибка: не удалось выполнить проверку подлинности. PHPMailerОшибка SMTP: не удалось выполнить аутентификацию. phpmailer

//------------------------- Mail to company section ----------------- 
$to='[email protected]'; 

$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 = "[email protected]"; //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 = "[email protected]"; //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 --------------------------------------- 
+0

Обновить до [недавней версии PHPMailer] (https://github.com/PHPMailer/PHPMailer), основывать свой код на [приведенном примере gmail] (https://github.com/PHPMailer/PHPMailer/blob /master/examples/gmail.phps) и [прочитать документы] (https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). – Synchro

ответ

1

Попробуйте изменить $mail->SMTPSecure = "tls"; и использовать в качестве $mail->Port = 587; также не забудьте включить доступ к вашей учетной записи GMAIL из внешнего приложения, вы должны получить приглашение по электронной почте на ваш счет GMAIL о попытке доступа.