PDA

View Full Version : PROBLEM: Sending emial using gmail server



Slesher
05 May 2011, 08:16 AM
Hello,

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 = "*******";

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


Any help would be greatly appreciated.