PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

[FIXED] how to get a batch file send a email using PHP?

 August 31, 2022     gmail, pear, php, smtp, ssl     No comments   

Issue

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


Solution

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



Answered By - ppant
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing