0
votes

For some time I was trying to create and send automatic email using php script and gmail server and I always get this error:

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

Here is my code:

   require_once ("mail.php");
   ini_set("SMTP","ssl://smtp.gmail.com");
   ini_set("SMTP_PORT", 465);
   $to = $sqlmail['email'];
   $from = $fromemail['email'];
   $body = "Hello, \n\n";
   $body .= "This is a request to borrow the following book\n";
   $body .= "Title: $title\n";
   $body .= "Author: $author\n";
   $body .= "Year: $year\n";
   $body .= "From the user $_SESSION[username]\n";
   $subject = $title . " " . $author . " " . $year;



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

   $headers = array ('From' => $from,
            'To' => $to,
            'Subject' => $subject);
   $smtp = new Mail();
   $smtp ->factory('smtp',
   array ('host' => $host,
         'port' => $port,
         'auth' => true,
         'username' => $username,
         'password' => $password));

   $mail = $smtp->send($to, $headers, $body);
1
It would be handy to see mail.php too.Nick Brunt
mail.php is the standard class. When you install php client it has mail.php inside of it. (Meaning i did not program it)Slesher

1 Answers

0
votes

If you can deliver to a local Postfix and let Postfix deliver to Gmail, you can try the solution, I've blogged about some time ago.