2017-06-03 9 views
0

Google SMTPとPHPMailerの最新バージョンでメールを送信する際に問題があります。ここではたくさんの質問がありますが、答えは私のためには機能しません。 フリーサブドメイン000webhostで無料ホスティングを使用しています。 これはPHPMailerドキュメントから電子メールを送信するための私の標準的なPHPコードです:メールを送信するSMTPのGmailとPHPMailer

$mail->isSMTP(); 
$mail->Host = 'smtp.gmail.com'; 
$mail->SMTPAuth = true; 
$mail->Username = 'GMAIL EMAIL ACCOUNT'; 
$mail->Password = 'MY PASSWORD FOR GMAIL EMAIL ACCOUNT'; 
$mail->SMTPSecure = 'tlc'; 
$mail->Port = 587; 
$mail->SMTPDebug = 3; 
$mail->setFrom('EMAIL ADDRESS', 'EXAMPLE'); 
$mail->addAddress('ADDRESS TO SEND', 'From contact form'); 

$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

と私はこのエラーを取得する:

.... 2017-06-03 15:15:33 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 203sm11822739ywk.62 - gsmtp 2017-06-03 15:15:33 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 203sm11822739ywk.62 - gsmtp 2017-06-03 15:15:33 SMTP Error: Could not authenticate. .....

私はポート465sslを使用する場合、私は同じエラーを参照してください。

私のGmailでは、メールアカウント2工場認証はOFFで、Allow less secure appsONです。

私は本当に何をすべきかわかりません。

+0

SMTPSecureに 'tlc'という設定はありません。 – Synchro

答えて

0

私はGoogle App Passwordの作成をする方法を発見し、Gmailに代わりアカウントのパスワードを、それを使用します。

$mail->Password = 'GOOGLE APP PASSWORD'; 

あなたがTwo factory authentication設定する必要があるアプリのパスワードを作成するには:あなたはアプリのパスワードを作成することができ、https://support.google.com/accounts/answer/185839?hl=enを - https://support.google.com/accounts/answer/185833?hl=en

関連する問題