1
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "******@gmail.com"; // your SMTP username or your gmail username
$mail->Password = "******"; // your SMTP password or your gmail password
$from = "***********@example.com"; // Reply to this email
$to="******@gmail.com"; // Recipients email ID
$name=" Name"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Webmaster"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Sending Email From Php Using Gmail";
$mail->Body = "This Email Send through phpmailer, This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}

このエラーが発生しています

SMTP エラー: 認証できませんでした。メーラー エラー: SMTP エラー: 認証できませんでした。

4

2 に答える 2

2

SSLを使用しているため。このコード行を追加します

$mail->SMTPSecure = 'ssl';

あなたも変える

$mail->Host = "ssl://smtp.gmail.com";

$mail->Host = "smtp.gmail.com";

また、拡張機能を有効にしているかどうかを確認してくださいphp_openssl.dll

于 2013-09-12T06:02:24.420 に答える
0

ユーザー名とパスワードが正しいことが確実な場合は、次の手順を実行します

1 $mail -> SMTPSecure = 'ssl';

2 $mail->Host = "smtp.gmail.com";

3 https://support.google.com/mail/answer/78754

4 Google アカウントに移動し、次にアプリを接続し、安全性の低いアプリに変更します。3番のすべての手順に従います。

于 2016-09-09T11:53:03.313 に答える