Solved

Configure PHP Pear Email. Connection Security: SSL/TLS

Posted on 2013-12-04
6
2,537 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 82

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 82

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 82

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

17 Experts available now in Live!

Get 1:1 Help Now