Solved

Configure PHP Pear Email. Connection Security: SSL/TLS

Posted on 2013-12-04
6
2,914 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to dynamically set the form action using jQuery.

724 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