stmp服务器php组件支持,问题发送电子邮件至谷歌的SMTP服务器(有自己的PHP脚本)...

我写了一个小PHP脚本连接到SMTP服务器和发送电子邮件。特别是连接到谷歌smtp服务器。显然,从下面显示的SMTPD设置出现了一些错误。问题发送电子邮件至谷歌的SMTP服务器(有自己的PHP脚本)

[data2] => 501 5.5.2 Cannot Decode response o47sm22737144eem.11

我在电子邮件正文中犯了一个错误,错误的格式? 下面是PHP脚本:

// SMTP settings

define('SMTP_SERVER', "ssl://smtp.gmail.com");

define('SMTP_PORT', '465');

define('SMTP_USER', '[email protected]'); // my gmail account

define('SMTP_PWD', 'XXX'); // my gmail password

class Mail

{

public static function send($smtpServer, $smtpPort, $smtpUser, $smtpPwd,

$from, $to, $subject, $message)

{

// Establish connection to SMTP server

$smtpConn = fsockopen($smtpServer, $smtpPort);

$smtpLog['connect'] = fgets($smtpConn);

// In case of success start SMTP communication

if ($smtpConn !== false)

{

// Say hello to SMTP

fputs($smtpConn, 'EHLO ' . $_SERVER['SERVER_ADDR'] . NL);

$smtpLog['hello'] = fgets($smtpConn);

// Require authentication

fputs($smtpConn, 'AUTH LOGIN' . NL);

$smtpLog['auth'] = fgets($smtpConn);

// Send username

fputs($smtpConn, base64_encode($smtpUser) . NL);

$smtpLog['user'] = fgets($smtpConn);

// Send password

fputs($smtpConn, base64_encode($smtpPwd) . NL);

$smtpLog['pwd'] = fgets($smtpConn);

// Send email from

fputs($smtpConn, "MAIL FROM: " . NL);

$smtpLog['from'] = fgets($smtpConn);

// Send email to

fputs($smtpConn, "RCPT TO: ". NL);

$smtpLog['to'] = fgets($smtpConn);

// Send "the email"

fputs($smtpConn, 'DATA' . NL);

$smtpLog['data1'] = fgets($smtpConn);

fputs($smtpConn,

"To: \r\nFrom: \r\nSubject: $subject\r\n$message\r\n.\r\n");

$smtpLog['data2'] = fgets($smtpConn);

fputs($smtpConn, 'QUIT' . NL);

$smtpLog['quit'] = fgets($smtpConn);

fclose($smtpConn);

}

return $smtpLog;

}

}

$log = Mail::send(SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PWD,

'[email protected]', '[email protected]', 'Subject', 'Message');

print_r($log);

而从谷歌的SMTP服务器的全响应日志:

[connect] => 220 mx.google.com ESMTP o47sm22737144eem.11

[hello] => 250-mx.google.com at your service, [XX.XX.XX.XX]

[auth] => 250-SIZE 35882577

[user] => 250-8BITMIME

[pwd] => 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2

[from] => 250 ENHANCEDSTATUSCODES

[to] => 334 XXX

[data1] => 334 XXX

[data2] => 501 5.5.2 Cannot Decode response o47sm22737144eem.11

[quit] => 530-5.5.1 Authentication Required. Learn more at

2012-10-29

Dalai

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值