Solved

Configure PHP Pear Email. Connection Security: SSL/TLS

Posted on 2013-12-04
6
2,606 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now