Solved

Configure PHP Pear Email. Connection Security: SSL/TLS

Posted on 2013-12-04
6
2,679 Views
Last Modified: 2013-12-05
I'm trying to get PHP to send an email. Decided the built-in PHP Mail function didn't return any useful error messages, so switched to trying the Pear Mail.

First, I can send an email from Thunderbird, configured as:
Outgoing Server (SMTP)
Server Name: smtp.cox.net
Port: 465
User Name: xxxx
Authentication Method: Normal password
Connection Security: SSL/TLS
(I'm replacing my email username with 'xxxx' for posting here)
Here's my test PHP code:
<?php
@require_once "Mail.php";

$recipients = 'xyzzy@ieee.org';

$headers['From']    = 'xxxx@cox.net';
$headers['To']      = 'xxxx@cox.net';
$headers['Subject'] = 'Test message';
$body = 'Test message';

// Define SMTP Parameters
$params['host'] = 'smtp.cox.net';
$params['port'] = 465;
$params['auth'] = "PLAIN";
$params['username'] = 'xxxx@cox.net';
$params['password'] = 'yyyy';
$params['debug'] = TRUE;

$smtp =  @Mail::factory('smtp', $params);
var_dump($smtp);

$mail = @$smtp->send($to, $headers, $body);
var_dump($mail);
 ?>

Open in new window

(again replacing email and password with 'xxxx' and 'yyyy' for posting here. It's correct in my actual code)
When testing the browser spins for a minute or more and finally gives this output:

object(Mail_smtp)#1 (13) {
 ["_smtp"]=> NULL
["_extparams"]=> array(0) { }
["host"]=> string(12)
"smtp.cox.net" ["port"]=> int(465)
["auth"]=> string(5) "PLAIN"
["username"]=> string(17) "xxxx@cox.net"
["password"]=> string(8) "xxxx"
["localhost"]=> string(9) "localhost"
["timeout"]=> int(5)
["debug"]=> bool(true)
["persist"]=> bool(false)
["pipelining"]=> NULL
["sep"]=> string(2) " " }
DEBUG: Send: QUIT
0
Comment
Question by:deleyd
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
goubun earned 500 total points
ID: 39697017
If you need to use SSL you need to change

$params['host'] = 'ssl://smtp.cox.net';

and

$params['auth'] = true;
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39697080
You should also remove the '@' in front of $smtp because you Do want the error messages while you're trying to get it to work.
$mail = $smtp->send($to, $headers, $body);

Open in new window

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39697089
I just noticed that you have '@' in two other places also.  You should remove them too because you Do want the error messages at this point.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:deleyd
ID: 39698361
"Failed to connect to ssl://smtp.cox.net: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: )]"
OK how do I enable ssl?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39698916
If you're on Windows, you need to enable "extension=php_openssl.dll" and restart.

This is the main page:
http://php.net/manual/en/book.openssl.php

This is the page for install with notes:
http://www.php.net/manual/en/openssl.installation.php
0
 

Author Closing Comment

by:deleyd
ID: 39699507
For anyone else:

To get SSL configured I edited php.ini and uncommented the line
extension=php_openssl.dll

Open in new window

and restarted the web server.

There are some nice User Contributed Notes explaining more at the end of
http://www.php.net/manual/en/openssl.installation.php
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question