如何在STMP服务器上进行连接和身份验证

时间:2020-10-21 00:57:01

标签: php email phpmailer email-validation

我需要使用电子邮件和密码连接到GMAIL SMTP服务器,而不发送电子邮件,然后收到200 OK。

我使用代码PHPMailer:

$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 = "myuser@gmail.com";
$mail->Password = "password";
$mail->SetFrom("");
$mail->Subject = utf8_decode("My subject");
$mail->Body = "hello";
$mail->AddAddress("destination@gmail.com");

$mail->Body = template('emails/reset-password', compact('comentario'));

if ($mail->Send()) {
  $mail->ClearAllRecipients();
  $mail->ClearAttachments();
}

我的脚本正在发送电子邮件,我只想验证身份验证。

1 个答案:

答案 0 :(得分:0)

PHPMailer本身并没有太多用处,因为它全部与发送有关。但是,PHPMailer的SMTP类可以很好地完成此任务,并且有a script provided with PHPMailer that does exactly as you ask。我不会在这里重现该脚本,因为它只会为我创建维护!

脚本连接到SMTP服务器,启动TLS,然后进行身份验证,仅此而已。