开发者

problem in sending mail by gmail smtp in server but works fine in localhost

I have opened a site in a free web hosting company which is not offering mail() facility so I have decided to implement this facility of sending emails using G-mail's SMTP server.

I have used PEAR' Mail package to send mails. It works fine locally but unfortunately its not all working in my website's server.

When the page is opened, it produces a blank wh开发者_运维知识库ite screen even no errors are being mentioned. You can check here to see the script run.

This is my code:

<?php

   require_once "Mail.php";

    $from = "username@gmail.com";
    $to = "username@yahoo.com";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

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

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

?>

Can anyone help me to understand what's going wrong?


You maybe forgot to upload the Mail.php file or one of the dependencies. A white page often indicates a fatal error.


Gmail blocks some web hosting providers. Contact you your web hosting provider.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜