Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pear Mail function not working?

Status
Not open for further replies.

tiamat2012

Programmer
Dec 12, 2004
144
US
Can anyone take a look at this code and tell me why?

Code:
require_once "Mail.php";

$from = "email@email.com";
$to = "email@toemail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.earthlink.net";
$username = "username@earthlink.net";
$password = "password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

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

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

It's telling me unable to connect to mail.earthlink.net:25, but I have used this type of thing before from an ASP.NET application, and earthlink sent it fine... can anyone see errors in the code?

-Kerry

P.S. the e-mails, username and password were changed from the valid ones.
 
some things to consider:

does earthlink authenticate to port 25? some smtp providers require smtp-auth connections on higher ports
does your php host allow outgoing port 25 connections? many don't.
try getting a more verbose error message by using
Code:
$mail->getDebugInfo()

instead of getMessage
 
I'm pretty sure that earthlink allows port 25 (i've used ASP.NET functions, and I think they use the same port), but not sure if this hosting provider llows outgoing port 25 connections, I'll send them a a message.

How exactly would I use getDebugInfo()? smtp is my object, but I don't know how I would get it at all.

-Kerry
 
instead of this
Code:
if (PEAR::isError($mail)) {
echo("<p>Error: " . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
use
Code:
if (PEAR::isError($mail)) {
echo("<p>Error: " . $mail->getDebugInfo() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
 
Thanks jpadie.


It doesn't display anything.

-Kerry
 
it may be that pear_mail does not populate this.

can you not use the standard mail() call from php? often your hosts provide access to something like postfix or the like.
 
Because I'm using a free hosting provider, they won't let me use the standard SMTP, so I was trying to use my earthlink accounts one...

-Kerry
 
so that does rather suggest that they will also have blocked outbound access to port 25!

have a look on earthlink's site, often provider's allow smtp access on a higher port for just these circumstances. in fact, i'd be pretty certain that a provider like them will allow inbound access on port 587 too.

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

to
Code:
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password
'port' => 587));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top