【问题标题】:How to connect and authenticate on the STMP server如何在 SMTP 服务器上连接和验证
【发布时间】:2021-02-03 20:59:18
【问题描述】:

我需要用邮箱和密码连接到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();
}

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

【问题讨论】:

  • 您对此进行过研究吗?

标签: php email phpmailer email-validation


【解决方案1】:

PHPMailer 本身并没有多大用处,因为它只用于发送。但是,作为 PHPMailer 一部分的 SMTP 类可以做到这一点,并且有 a script provided with PHPMailer that does exactly as you ask。我不会在这里复制脚本,因为它只是为我创建维护!

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

【讨论】:

  • 你有链接吗?因为我用 PHPMailer 的测试不起作用。
  • 我的回答中有链接吗?
  • 我没有使用 Laravel。我正在使用结构化 PHP,而不是对象。
  • 我给你的链接与 Laravel 无关。这是一个完全独立的脚本,它使用 PHPMailer 的 SMTP 类,这正是您所要求的。
猜你喜欢
  • 2010-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-08
相关资源
最近更新 更多