0

I write code send mail using PHPMailer

include 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug  = 1;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'example1@gmail.com';
$mail->Password = 'password';
$mail->SetFrom('example2@gmail.com', 'Admin');
$mail->AddReplyTo('example@yahoo.com', 'Name');
$mail->AddAddress('xample3@gmail.com');
$mail->Subject = 'Active email';
$mail->MsgHTML('Click the link to active');
$mail->Send();

When I use browser it can send mail, but in command prompt,

php path_to_file

it is not working,the error is:

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport ssl"....
Hoclamweb
  • 11
  • 1
  • 3

4 Answers4

0

Maybe you have two different php.ini files, one for your http server and one for your command line client.

Do a <?php phpinfo(); ?> and check in browser and command line which php.ini is loaded.

Output should be something like "Loaded Configuration File c:\xampp\php\php.ini"

Related Question: How to find the php.ini file used by the command line?

Community
  • 1
  • 1
Kaffee
  • 1,563
  • 11
  • 21
0

I think Anthony Sterling is corretn. You can try this. Locate where is your php.ini file for cli. Use following command

php -i | grep php.ini

it will show the path of ini file for Php CLI

Add following line there

extension=php_openssl.dll

and It should work. I have not tested it yet. Please feel free to change if anything is wrong.

Abani Meher
  • 564
  • 3
  • 17
  • A system restart isn't required. (This isn't MS software :P) For the CLI the change should take effect immediately. If it's an Apache server, only the Apache server has to be restarted. – Atli Jul 01 '13 at 09:53
0

I'd guess it's your PHP configuration. The HTTP server and the command line aren't using the same file, and the one used by the command line is missing the include of the openssl extension.

Use the phpinfo() function in your command line to find out which file it is using:

php -r "phpinfo();"

Then look for the "Loaded Configuration File" line to see which file it's using. If this is a Windows server, you just need to go into that file and add the openssl extension by appending this to it:

extension=php_openssl.dll

And make sure the extension_dir is set to the the correct path; which is the "ext" directory of the PHP installation dir.

Atli
  • 7,855
  • 2
  • 30
  • 43
0

Php command line need a php.ini to load extension like openssl. I use Wamp and the php.ini file used by Apache is not the same file used by the php command line.

php.ini file used by Apache is in : C:\wamp\bin\apache\apache2.X.X\bin

AND

php.ini file used by your command line is in : C:\wamp\bin\php\phpX.X.XX

Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
Naxxan60
  • 7
  • 7