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

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

问题描述

我是PHP的新手。我试图通过PHPmail发送自己一个示例电子邮件。我使用的是gmail的smtp服务器。我正在尝试从我的Gmail帐户发送一个样本邮件到我的雅虎帐户。但是我收到错误: Mailer错误:SMTP connect()失败。

这里是代码:

 <?php 

需要class.phpmailer.php;
$ mail = new PHPMailer();
$ mail-> IsSMTP(); //通过SMTP发送
$ mail-> Host =ssl://smtp.gmail.com;
$ mail-> SMTPAuth = true; //打开SMTP验证
$ mail->用户名=myemail@gmail.com; // SMTP username
$ mail-> Password =mypassword; // SMTP password
$ webmaster_email =myemail@gmail.com; //回复此电子邮件ID
$ email =myyahoomail@yahoo.in; //收件人电子邮件ID
$ name =我的名字; //收件人的名字
$ mail-> From = $ webmaster_email;
$ mail-> Port = 465;
$ mail-> FromName =我的名字;
$ mail-> AddAddress($ email,$ name);
$ mail-> AddReplyTo($ webmaster_email,我的名字);
$ mail-> WordWrap = 50; // set word wrap
$ mail-> IsHTML(true); //发送为HTML
$ mail-> Subject =subject;
$ mail-> Body =
这是HTML BODY; // HTML Body
$ mail-> AltBody =这是用户以纯文本格式查看的正文; // Text Body

if(!$ mail-> Send())
{
echoMailer Error:。 $ MAIL-> ERRORINFO;
}
else
{
echo已发送消息;
}
?>

我在Windows 7 64位机器上使用WAMP服务器。有什么可能的?

请帮我解决这个问题。谢谢!

解决方案

您需要添加主机参数

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

另外,检查是否有 open_ssl 已启用。

 <?php 
echo!extension_loaded('openssl')?不可用:可用 ;


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";
}
?>

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

解决方案

You need to add the Host parameter

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

Also, check if you have open_ssl enabled.

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

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

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