Solved

Configure PHP Pear Email. Connection Security: SSL/TLS

Posted on 2013-12-04
6
2,740 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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