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条)

报告相同问题?

悬赏问题

  • ¥15 halcon联合c#遇到了问题不能解决
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?