【问题标题】:PHPMailer with Gmail SMTP settings带有 Gmail SMTP 设置的 PHPMailer
【发布时间】:2014-02-19 05:05:22
【问题描述】:

我正在尝试通过我的 Gmail 帐户使用 PHPMailer 脚本创建一个联系表单。我已经尝试了$Mail->SMTPSecure = "ssl";$Mail->Port = 465;$Mail->SMTPSecure = "tls";$Mail->Port = 587;。我还在想:

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (43443944) SMTP Error: Could not connect to SMTP host.

下面的代码是我正在试用的。还有什么我可以尝试的,或者其他可能有解决方案的帖子吗?先感谢您。

$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

$MessageTEXT = 'This is the alternate to HTML' ;

function SendMail( $ToEmail, $MessageHTML, $MessageTEXT ) {
  require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
  $Mail = new PHPMailer();
  $Mail->IsSMTP(); // Use SMTP
  $Mail->Host        = "smtp.gmail.com"; // Sets SMTP server
  $Mail->SMTPDebug   = 2; // 2 to enable SMTP debug information
  $Mail->SMTPAuth    = TRUE; // enable SMTP authentication
  $Mail->SMTPSecure  = "ssl"; //Secure conection
  $Mail->Port        = 465; // set the SMTP port
  $Mail->Username    = 'thefloatingorange06@gmail.com'; // SMTP account username
  $Mail->Password    = 'password'; // SMTP account password
  $Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
  $Mail->CharSet     = 'UTF-8';
  $Mail->Encoding    = '8bit';
  $Mail->Subject     = 'Test Email Using Gmail';
  $Mail->ContentType = 'text/html; charset=utf-8\r\n';
  $Mail->From        = 'jackiesylee@gmail.com';
  $Mail->FromName    = 'GMail Test';
  $Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

  $Mail->AddAddress( $ToEmail ); // To:
  $Mail->isHTML( TRUE );
  $Mail->Body    = '$name $email $message';
  $Mail->AltBody = $MessageTEXT;
  $Mail->Send();
  $Mail->SmtpClose();

  if ( $Mail->IsError() ) { // ADDED - This error checking was missing
return FALSE;
  }
  else {
return TRUE;
  }
}

$ToEmail = 'thefloatingorange06@gmail.com';
$ToName  = 'Jackie';

$Send = SendMail( $ToEmail, $name, $email, $message, $MessageTEXT );
if ( $Send ) {
  echo "<h2> Sent OK</h2>";
}
else {
  echo "<h2> ERROR</h2>";
}
die;
?>

【问题讨论】:

  • 您是否希望我们相信您实际上已经阅读了错误消息?如果是这样,您在哪里以及如何启用 SSL?
  • 是的,这是我输入$Mail-&gt;Port = 465$Mail-&gt;SMTPSecure = "ssl" 时出现的错误消息。我不确定您在哪里以及如何启用 SSL,但如果这是我需要做的事情,您能否指出正确的方向?
  • 快速谷歌搜索出现stackoverflow.com/questions/1705856/…

标签: smtp gmail phpmailer


【解决方案1】:

下面的代码对我有用:

$mail->IsSMTP(); // Use SMTP
$mail->Host        = "smtp.gmail.com"; // Sets SMTP server
$mail->SMTPDebug   = 2; // 2 to enable SMTP debug information
$mail->SMTPAuth    = TRUE; // enable SMTP authentication
$mail->SMTPSecure  = "tls"; //Secure conection
$mail->Port        = 587; // set the SMTP port
$mail->Username    = 'example1@gmail.com'; // SMTP account username
$mail->Password    = 'password'; // SMTP account password
$mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$mail->Encoding    = '8bit';
$mail->Subject     = 'Test Email Using Gmail';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->From        = 'example@dominio.com';
$mail->FromName    = 'GMail Test';
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    • 2019-05-30
    • 2014-09-16
    • 1970-01-01
    相关资源
    最近更新 更多