SMTP: Failed to connect socket: Connection Refused
Just because you are listening on a port doesn't mean you can access it. A firewall either on the system or an upstream inline device could be block it.
From you local machine that you are running the script from, do telnet mail.example.com 587
and are you brought to a prompt?
atb
Updated on June 04, 2022Comments
-
atb almost 2 years
I'm trying to send an email in PHP using PEAR Mail package and SMTP, but I keep getting the error
SMTP: Failed to connect socket: Connection Refused
I don't really know anything about how SMTP works, so bear with me.
Here is my code:
$recipients = $_SESSION['email']; $headers["From"] = "[email protected]"; $headers["To"] = "[email protected]"; $headers["Subject"] = 'Subject Text!'; $mailmsg = $_SESSION['body']; /* SMTP server name, port, user/password */ $smtpinfo["host"] = "mail.example.com"; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo["username"] = $email_user; $smtpinfo["password"] = $email_pass; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $send = $mail_object->send($recipients, $headers, $mailmsg); if (PEAR::isError($send)) { echo '<p>Error: ' . $send->getMessage() . '</p>'; } else { header('Location: ../../emailed.php'); }
What I know is:
Domain is hostgator, and the email handler is Keiro Connect.
I'm not sure which port to go through. I looked at the services, and it says that the Listening IP Addresses are:
- SMTP: All addresses:25, All addresses:587
- Secure SMTP: All addresses:465
- SMTP Submission: All addresses:587 *this service is turned off though
I've also noted that SMTP delivery is set to deliver directly using DNS MX records. I don't know if that means anything.
What am I doing wrong? What should I be looking for so I can get all the parameters in order? Any help would be greatly appreciated.
-
atb almost 12 yearsThe prompt is: Trying: XXX.XX.X.XXX... Connected to waiter.example.com. Escape character is '^]'. 220 waiter.example.com Kerio Connect 7.4.1 ESMTP ready
-
Mike Mackintosh almost 12 yearsOk, great! That means that you are able to establish a connection to the server. Next, does
$email_user
include the @domain.com? -
atb almost 12 yearsNo, just the username before @domain.com