Jump to content

Can't Send Mail Using SSL Encryption (Pear)


NewPHPFreak

Recommended Posts

Hi...

 

I'm new to PHP and to Pear (and to phpfreaks).

 

My environment is...

Win XP,

Apache 2.2,

PHP 5.2.9-2,

Pear 1.8.1,

 

And, phpinfo() confirms that openssl is enabled.

 

If I change the following code to use an SMTP server (mailhost.att.net) that does NOT require an SSL connection or authentication (with 'auth' => false and $port = "25"), it works just fine  ;D.

 

But if I run the code as shown, to send mail to an SMTP server that requires a SSL connection with authentication (imailhost.worldnet.att.net), it does not work  ???.  I get no output at all from the script, and no mail gets sent.  In previous attempts with similar code, I got an error in my browser that said the server was rejecting the connection. 

 

I'm using the same username, password, port, and SSL encryption in a mail client, and I have no trouble sending mail to the imailhost.worldnet.att.net server, so I'm pretty confident it's my script or something related to php or pear on my machine.

 

One possible clue is that when I comment out the entire $smtp = Mail::factory() statement, I can get phpinfo() output to my browser, although, obviously, the message does not get sent to the SMTP server.

 

FYI, att.net requires the use of SSL and authentication to use their mail servers if you are connecting to them thru another ISP.

 

Here's the code I'm using...

 

<html>
<body>

<?php

phpinfo();
require_once "Mail.php";

$from = "Me <[email protected]>";
$to = "Them <[email protected]>";
$subject = "Hi!";
$body = "Hello World.";

$host = "imailhost.worldnet.att.net";
$port = "465";
$username = "my.at&t.username";
$password = "mypassword";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);


$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));


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

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Message successfully sent!</p>");
}

?>

</body>
</html>

 

 

Any assistance would be appreciated !

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.