0

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 ~~~~~~~

Community
  • 1
  • 1
ppant
  • 137
  • 3
  • 13
  • Are you absolutely sure you have openssl enabled? I don't mean installed, but enabled, it should show up on your phpinfo page – Tomáš Plešek Dec 09 '11 at 10:44
  • Yes: It reads as below: OpenSSL support enabled OpenSSL Library Version OpenSSL 0.9.8r 8 Feb 2011 OpenSSL Header Version OpenSSL 0.9.8r 8 Feb 2011 – ppant Dec 09 '11 at 10:47
  • Tomas, when I use my browser to execute the php script.. it works fine.. however when I use the batch file to run the same, it shows the error I described above – ppant Dec 09 '11 at 10:52
  • Oh i din't know that. Allright then. How are you executing your PHP, mod_php on server and php cli using the script? There could be a difference – Tomáš Plešek Dec 09 '11 at 10:53
  • I dont know about that.. whats the difference? – ppant Dec 09 '11 at 10:57
  • Well, the're different ways to execute PHP. mod_php interfaces with php libraries from webserver, however standalone php is an executable. You have to elaborate on your running environment, i.e.: what web server are you using, how are you executing the scheduled script, etc. – Tomáš Plešek Dec 09 '11 at 11:00
  • @Tomas I am using Windows Vista and running WAMP Server 2, APACHE 2.2.21 and PHP 5.3.8. I am using Windows Task Scheduler to run the batch file.. I am not very familiar with servers and execution of PHP.. I am just good at logical programming – ppant Dec 09 '11 at 11:02
  • Okay. Now, how are you executing the batch file, like this? C:/PHP/php.exe myscript.php? – Tomáš Plešek Dec 09 '11 at 11:04
  • 1
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5713/discussion-between-tomas-plesek-and-prashant) – Tomáš Plešek Dec 09 '11 at 11:05
  • Thanks Tomas, I got it.. without your help I would not have been able to achieve this!! – ppant Dec 09 '11 at 11:40
  • @Prashant Please answer your own question and accept your own answer, to close the question off tidily – DaveRandom Dec 09 '11 at 11:59
  • I recommend someone answers the question and it gets accepted, it will definitely help other users more, since that's the way this site works! – Khez Dec 09 '11 at 12:09

1 Answers1

2

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 ~~~~~~~

ppant
  • 137
  • 3
  • 13