【问题标题】:Send email using the GMail SMTP server from a Unix weberver website using php使用 php 从 Unix weberver 网站使用 GMail SMTP 服务器发送电子邮件
【发布时间】:2014-06-27 13:16:11
【问题描述】:

我正在尝试使用以下 php 代码发送 SMTP 电子邮件。

    <?php

require_once "Mail.php";


$from = "info@XXXXX.com";
$to = "info@XXXXXX.com";
$subject = "Hi";
$body = "Hi,\n\nHow are you?\nDoing anything this Friday evening?\n";

 $host = "ssl://smtp.gmail.com";
 $port = "465";
$username = "xxxxx";
$password = "xxxxx";

$headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);

 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password)); 

$mail = $smtp->send( $to, $headers, $body );

if ( PEAR::isError($mail) ) {
echo( "<p>" . $mail->getMessage() . "</p>" );
} else {
echo( "<p>Message successfully sent!</p>" );
}

 ?>

当我从 unix webserver 网页执行代码时。我收到以下错误。

authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]

但上面的代码在我的本地主机上运行良好。

请帮我完成这个项目。

谢谢。

【问题讨论】:

  • “Mail.php”里面有什么,你的代码还是来自某个框架?
  • 身份验证数据不正确 - 听起来您可能已将某些内容从本地主机更改为生产环境。检查用户名和密码。
  • @Peter:我从 pear.php.net 下载了代码。 Mail.php 没有任何变化
  • @esqew:相同的用户名和密码凭证从本地主机工作。

标签: php email unix ssl smtp


【解决方案1】:

我有同样的问题,你应该在 G-Suite 中启用 SMTP,更多细节在这里: https://support.google.com/a/answer/2956491?hl=en

【讨论】:

    猜你喜欢
    • 2014-10-28
    • 2016-09-07
    • 2010-10-17
    • 1970-01-01
    相关资源
    最近更新 更多