LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   PHP mail not connecting to SMTP server but can connect with telnet (https://www.linuxquestions.org/questions/linux-server-73/php-mail-not-connecting-to-smtp-server-but-can-connect-with-telnet-509345/)

mrJimmbo 12-11-2006 06:33 AM

PHP mail not connecting to SMTP server but can connect with telnet
 
Hi everbody.

I've scoured google for any hint of what I might be doing wrong to no avail!

I have been using the PHP mail() function quite happily for a while but I want to send mail via an SMTP server, either installed on another box or a remote one(eg ISP's server).

I get an error "unable to connect to smtp server etc etc"

The weird thing is that I can connect to which ever smtp server I'm try in the script with telnet so I know that port 25 isn't being blocked by my ISP.

The script I'm using is very simple, using the Pear mail package pretty much like this:

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@email.com>";
$to = "Ramona Recipient <reciever@email.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "smtp.host.com";
//$port = 25; default 25
$username = "username";
$password = "password";

$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>");
}
?>

Is there any other files like hosts or network etc that could affect this?

Maybe I should just start from scratch again?

Any help would be greatly appreciated!!

mrJimmbo 12-12-2006 05:51 PM

Anybody.... nobody

Yeah it's a weird one. Everything I found on the net with the same problem basically had their ISP blocking port 25...


All times are GMT -5. The time now is 04:14 PM.