【问题标题】:Send mail from localhost to Gmail从本地主机发送邮件到 Gmail
【发布时间】:2016-04-14 10:30:16
【问题描述】:

如何让 gmail 接受来自 localhost 的 phpmailer 并且不阻止登录?

我该如何解决这个错误信息

无法发送邮件。Mailer 错误:SMTP connect() 失败。

<?php
require 'PHPMailer-master\PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'my@gmail.com';                 // SMTP username
$mail->Password = 'valid';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('my@gmail.com', 'me');
 // Add a recipient
  $mail->addAddress('their@gmail.com');               // Name is optional
  $mail->addReplyTo('my@gmail.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');


 $mail->isHTML(true);                                  // Set email format to HTML

 $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';
   }

   ?>

【问题讨论】:

  • 你试过25端口吗?
  • 你的 PHP 版本是什么 ..?
  • 你也可以试试端口 465 SSL support.google.com/a/answer/176600?hl=en
  • 我只使用谷歌商业应用程序完成了这项工作。个人帐户也适用于此吗?

标签: php email ssl


【解决方案1】:

似乎没有在端口 587 上建立与 Google SMTP 的连接。您是否处于端口 587 被阻止的网络中。您可以使用以下 telnet 命令简单地检查是否可以建立连接:

telnet smtp.gmail.com 587

您将收到如快照所示的响应

Windows 中的 Telnet 客户端默认禁用,需要通过 Windows 的程序和功能启用:

控制面板 --> 程序 --> 打开或关闭 Windows 功能,在弹出的对话框中勾选“Telnet 客户端”。

或者你可以下载Putty

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-12
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    相关资源
    最近更新 更多