SMTP 连接()失败 PHPmailer - PHP [英] SMTP connect() failed PHPmailer - PHP

查看:31
本文介绍了SMTP 连接()失败 PHPmailer - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PHP 新手.我试图通过 PHPmailer 给自己发送一封示例电子邮件.我正在使用 gmail 的 smtp 服务器.我正在尝试将示例邮件从我的 gmail 帐户发送到我的 yahoo 帐户.但我收到错误:Mailer Error: SMTP connect() failed.
这是代码:

I am new to PHP. I was trying to send myself a sample e-mail through PHPmailer. I am using gmail's smtp server. I am trying to send a sample mail from my gmail account to my yahoo account. But I am getting the error : Mailer Error: SMTP connect() failed.
Here is the code :

<?php

require "class.phpmailer.php";
$mail = new PHPMailer(); 
$mail->IsSMTP();                              // send via SMTP
$mail->Host = "ssl://smtp.gmail.com";
$mail->SMTPAuth = true;                       // turn on SMTP authentication
$mail->Username = "myemail@gmail.com";        // SMTP username
$mail->Password = "mypassword";               // SMTP password
$webmaster_email = "myemail@gmail.com";       //Reply to this email ID
$email="myyahoomail@yahoo.in";                // Recipients email ID
$name="My Name";                              // Recipient's name
$mail->From = $webmaster_email;
$mail->Port = 465;
$mail->FromName = "My Name";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"My Name");
$mail->WordWrap = 50;                         // set word wrap
$mail->IsHTML(true);                          // send as HTML
$mail->Subject = "subject";
$mail->Body = "Hi,
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";
}
?>

我在 Windows 7 64 位机器上使用 WAMP 服务器.可能是什么问题?
请帮我解决这个问题.谢谢!

I am using WAMP server on a Windows 7 64-bit machine. What could be the prob?
Please help me solve this. Thanks!

推荐答案

需要添加Host参数

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

另外,检查您是否启用了 open_ssl.

Also, check if you have open_ssl enabled.

<?php
echo !extension_loaded('openssl')?"Not Available":"Available";

这篇关于SMTP 连接()失败 PHPmailer - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆