从PHP页面使用GMail SMTP服务器发送电子邮件

从PHP页面使用GMail SMTP服务器发送电子邮件

我试图从PHP页面通过GMail的SMTP服务器发送电子邮件,但是我收到此错误:

身份验证失败[SMTP:SMTP服务器不支持身份验证(代码:250,响应:mx.google.com为您服务,[98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]

有人可以帮忙吗?这是我的代码:

<?php

require_once "Mail.php";


$from = "Sandra Sender <sender@example.com>";

$to = "Ramona Recipient <ramona@microsoft.com>";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";


$host = "smtp.gmail.com";

$port = "587";

$username = "testtest@gmail.com";

$password = "testtest";


$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>");

 }

?>


倚天杖
浏览 1825回答 4
4回答
打开App,查看更多内容
随时随地看视频慕课网APP