dousi1875 2011-10-31 17:51
浏览 38

phpmailer SMTP错误

I am using this php code to send email through gmail account . but its showing smtp error . I have googled it . but not found any specific answer . would anyone please help to find the solution ??

I have hosted this code in my webserver

error : "SMTP Error: Could not connect to SMTP host. Message was not sent Mailer Error: SMTP Error: Could not connect to SMTP host.SMTP Error: Could not connect to SMTP host."

code:

<?php
require("class.phpmailer.php");

$email = $_POST['email_address'];

$username = 'username@gmail.com';  //your gmail address
$password = 'password';  //password


send_mail_to_subscriber();


function send_mail_to_subscriber()
{

    global $username,$password,$email;
    $mailer = new PHPMailer();
    $mailer->IsSMTP();
    $mailer->Host = 'ssl://smtp.gmail.com:465';
    $mailer->SMTPAuth = TRUE;

    $mailer->Username = $username;  
    $mailer->Password = $password;  
    $mailer->From = $username;  
    $mailer->FromName = $username; 

    $mailer->Body = 'this is a message';
    $mailer->Subject = 'this is a subject';
    $mailer->AddAddress($email);  
    if(!$mailer->Send())
    {
       echo "Message was not sent<br/ >";
       echo "Mailer Error: " . $mailer->ErrorInfo;
    }
    else
    {
       echo "Download link has been sent to your email address";
    }
}


?>
  • 写回答

2条回答 默认 最新

  • doujishan2247 2011-10-31 17:54
    关注

    Change your Host and add the following:

    $mailer->SMTPSecure = 'ssl';
    $mailer->Host = 'smtp.gmail.com';
    $mailer->Port = 465;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测