无法使用Mail.php通过谷歌smtp服务器发送邮件

时间:2013-05-27 05:31:13

标签: php email smtp gmail mailer

我的页面php代码就是这个

`

   require_once "Mail.php";

    $from = "<pramodkumar.damam73@gmail.com>";
    $to = "<pramodkumar.damam73@gmail.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "pramodkumar.damam73@gmail.com";  //<> give errors
    $password = "mypassword";

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

?>`

最初它显示许多错误,说isError和发送函数不是静态的。所以我将PEAR.php和Mail.php的函数修改为静态。但现在我收到了像

这样的错误
Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (code: -1, response: )]

请解决我的问题。

0 个答案:

没有答案