-4

Possible Duplicate:
PHP mail using Gmail

code :

<?
    //change this to your email.
    $to = "bhavesh412@gmail.com";
    $from = "bhavesh412@gmail.com";
    $subject = "Hello! This is HTML email";

    //begin of HTML message
    $message = <<<EOF
<html>
  <body bgcolor="#DCEEFC">
    <center>
        <b>Looool!!! I am reciving HTML email......</b> <br>
        <font color="red">Thanks Mohammed!</font> <br>
        <a href="http://www.maaking.com/">* maaking.com</a>
    </center>
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
  </body>
</html>
EOF;
   //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";

    //options to send to cc+bcc
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]";

    // now lets send the email.
    ini_set("SMTP","smtp.gmail.com");
    ini_set("smtp_port","465");
    mail($to, $subject, $message, $headers);

    echo "Message has been sent....!";
?>

I am getting below error:

Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\testMail.php on line 31

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\testMail.php on line 33

Community
  • 1
  • 1
Shah.Bhavesh
  • 19
  • 1
  • 7
  • 3
    As far as I know, Google's SMTP server requires authentication as well as using an encrypted (SSL/TLS) connection. You can't just point to smtp.gmail.com with 2 or 3 headers and send emails. – Narf Sep 07 '11 at 08:42
  • thank you guys m just new to php can say just 1st day so trying diff stuff thnaks for ur guidance – Shah.Bhavesh Sep 07 '11 at 09:13

3 Answers3

1

Gmail servers use TLS and login/password authentification, you can't use them with PHP's mail() function.

Try using a mail library like Swiftmailer. Here is an example that may work with Gmail: http://swiftmailer.org/wikidocs/v3/connections/smtp

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
0

You need to use SMTP authorization for gmail's SMTP server to work which you can't do with mail.

Take a look at PHPMailer they have a good example here.

fire
  • 21,383
  • 17
  • 79
  • 114
0

sometimes an isp provides free smtp service for their clients to some degree. google yourisp & smtp.