Hi,

I am trying to send email in php for which i installed PEAR mail package. The installation is fine but when i try to run the email script, i get this error :

Failed to connect to smtp.csaauto.com:25 [SMTP: Failed to connect socket: No connection could be made because the Failed to connect to smtp.csaauto.com:25 [SMTP: Failed to connect socket: No connection could be made because the target machine actively refused it. (code: -1, response: )]

Please let me know where the problem is. It would be of great help!
Here's my code:

<?php
require_once "Mail.php";

$from = "Matthew Sender <matt@csaauto.com>";
$to = "Mike Recipient <mike@csaauto.com>";
$subject = "Hi!";
$body = "Testing";

$host = "smtp.csaauto.com";
$username = "admin@csaauto.com";
$password = "admin1234";

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

if (PEAR::isError($smtp)) 
        die("Here's your error right here: " . $smtp->getMessage()); 

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

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

Recommended Answers

All 5 Replies

It means the mail server doesn't allow you to relay email. Either it is disabled, or your username/password is incorrect, or it is on a different port, or possiby even because the username is not the from address.

Thanks for the reply !

I know the username and password is correct, it is enabled coz it is able to send mails from Access 2007 database. How can i check the port on which is it running?

Thanks for the reply !

I know the username and password is correct, it is enabled coz it is able to send mails from Access 2007 database. How can i check the port on which is it running?

The port number you can get it from your webserver host, Try creating a new dummy email id from your cpanel, then it will gives you all the details(Including port, host, server name, accessurl for webmail).

Everything seems to be right : the port number, the username and password, but still the error persists. Any other solution?

Check the log files of your email server and look if you can find the reason it is refusing the connection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.