I have found numerous posts on Stacked overflow and other forums regarding sending the email using a batch file like: Send email using the GMail SMTP server from a PHP page
But none seems to work for me... I have been able to schedule task.. using Windows task scheduler and wrote the batch file:
@echo start C:\wamp\bin\php\php5.3.1\php.exe -f C:\wamp\www\email.php
PHP file shows a simple script as below:
<?php
require_once "Mail.php";
$from = "Prashant Yahoo <prashant.balan@yahoo.co.in>";
$to = "Prashant Hotmail <prashant.balan@hotmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl:\\smtp.gmail.com";
$port = "465";
$username = "<user@gmail.com>"; or user.gmail.com as stated in the above SO link
$password = "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>");
}
?>
I have PEAR setup on my local host already and everything I need. I even downloaded the latest OpenSSL and replaced the necessary files and as directed here and set environment variables: http://raibledesigns.com/wiki/Wiki.jsp?page=ApacheSSL
I receive the following error:
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: )]
How to solve this? Please help..
ANSWER OPEN YOUR PHP.INI FILE INSIDE THE C:\PHP or in my case C:\WAMP\BIN\PHP\PHP 5.3.8 and remove the semi-colon's ahead of: extension=php_openssl.dll and extension=php_sockets.dll Hope this would help someone else! ~~~~~~ Special Thanks to Tomas ~~~~~~~