drno94939847 2010-11-16 21:39 采纳率: 0%
浏览 100
已采纳

无法使用php pear mail()通过gmail发送电子邮件

I am attempting to send mail through my gmail account from a Dedicated Godaddy server. I have attempted to send email through my company's email server but Godaddy kills port 25 with no workaround (grrr).

I have searched high and low for a solution to this including here but am unable to send any emails. I always get an 'Authentication Required' error from google.

Here is the code I use to send the email:

include("Mail.php");

/* mail setup recipients, subject etc */

$headers["From"]   = "xxxxx@gmail.com";
$headers["to"]    = "yyyyy@hotmail.com";
$headers["subject"]   = "User feedback";   
$mailmsg    = "Hello, This is a test.";

/* SMTP server name, port, user/passwd */

$smtpinfo["host"]   = "ssl://smtp.gmail.com";   
$smtpinfo["port"]   = 465;    
$smtpinfo["auth"]   = true;    
$smtpinfo["username"]   = "xxxxx@gmail.com";
$smtpinfo["password"]   = "xxxxxx";
$smtpinfo["debug"]  = true;

/* Create the mail object using the Mail::factory method */

// $mail_object =& Mail::factory("smtp", $smtpinfo);
// EDIT -- removed reference   


$mail_object = Mail::factory("smtp", $smtpinfo);

/* Ok send mail */

$result = $mail_object->send($recipients, $headers, $mailmsg);

if(PEAR::isError($result))
{
 echo "
error sending mail: ".PEAR_Error::getCode().' '.PEAR_Error::getMessage();
}
else    
 echo "
Successfully sent mail.";

Here is the response from pear mail:

DEBUG: Recv: 250-mx.google.com at your service, [208.109.190.226]
DEBUG: Recv: 250-SIZE 35651584
DEBUG: Recv: 250-8BITMIME
DEBUG: Recv: 250-AUTH LOGIN PLAIN XOAUTH
DEBUG: Recv: 250 ENHANCEDSTATUSCODES
DEBUG: Send: MAIL FROM:<xxxxx@gmail.com>

DEBUG: Recv: 530-5.5.1 Authentication Required. Learn more at
DEBUG: Recv: 530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 t35sm1037116qco.30

Fatal error: Using $this when not in object context in /usr/share/php/PEAR.php on line 970

Any help is greatly appreciated.

  • 写回答

2条回答 默认 最新

  • doudong0425 2010-12-03 21:12
    关注

    The solution is... there is no solution since Godaddy was doing blocking. No way to get around it so I ended up using their 'approved' mail delivery server. grrr.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?