• Welcome to Web Hosting Forum - A Web Hosting Community for Webmasters.
 

Recommended Providers



WordPress Hosting

Jetpack
Fully Managed WordPress Hosting
lc_banner_leadgen_3
Fully Managed WordPress Hosting

WordPress

Forum Membership

Forum Membership

PHPMailer error :: unable to connect to server

Started by John, April 13, 2008, 07:37:19 PM



John

Hi,

I am having problem with phpmailer script. A simple phpmailer script gives an error:

Warning: fsockopen() [function.fsockopen]: unable to connect to mail.domain.com:25 in /home/user/public_html/class.smtp.php on line 122

Message was not sent

Mailer Error: SMTP Error: Could not connect to SMTP host.

I have no problem to connect to mail server using port 25. I can send mail using Email client. Also, I am able to telnet to this port.

I have tried to find the solution but did not get any fix.

Regards,

John

Kailash

#1
It could be PHP version problem. Try to downgrade the version of PHP and then try. If it doesn't help try to downgrade Apache version if you are using latest one.

Akshay_M

The error message you provided suggests that PHPMailer is unable to connect to your SMTP server at "mail.domain.com" on port 25. Since you can connect to the SMTP server using telnet and send emails using an email client, the issue might be related to PHPMailer's configuration. Here are some troubleshooting steps to help you resolve this problem:

Check SMTP Server Address:
Ensure that "mail.domain.com" is the correct SMTP server address. Verify that there are no typos in the hostname.

Check Port Number:
Confirm that port 25 is the correct SMTP port for your server. Some SMTP servers use different ports, such as 587 or 465. Make sure you are using the correct port in your PHPMailer script.

SMTP Authentication:
Many SMTP servers require authentication. Ensure that you have provided the correct SMTP username and password in your PHPMailer script. You can set these credentials using PHPMailer's Username and Password properties.

SSL/TLS Settings:
Some SMTP servers use SSL/TLS encryption for secure communication. If your SMTP server requires SSL/TLS, make sure you have configured PHPMailer accordingly. You can use the SMTPSecure property to specify the encryption type (e.g., "ssl" or "tls").

php
Copy code
$mail->SMTPSecure = 'ssl'; // or 'tls' if that's what your server requires
Verify Server Connectivity:
Double-check that your server allows outbound connections on port 25. Sometimes, hosting providers or firewalls may restrict outgoing traffic on specific ports.

DNS Resolution:
Ensure that your server can resolve the hostname "mail.domain.com" to the correct IP address. You can use the ping command or PHP's gethostbyname() function to verify DNS resolution.

Firewall and Security Software:
Check if there are any firewall or security software configurations that might be blocking outgoing connections from your web server on port 25.

PHP Version Compatibility:
Ensure that your PHP version is compatible with the version of PHPMailer you are using. Updating PHPMailer to the latest version might also resolve compatibility issues.

Error Logging:
Enable error logging in PHPMailer to get more detailed error messages. This can help you pinpoint the exact issue. You can use PHP's error_reporting and ini_set functions to enable error logging in your script.

php
Copy code
error_reporting(E_ALL);
ini_set('display_errors', 1);
SMTP Debugging:
Enable SMTP debugging in PHPMailer to capture detailed SMTP transaction logs. This can provide valuable information about the connection attempt and any error messages.

php
Copy code
$mail->SMTPDebug = 2;
After making these checks and adjustments, run your PHPMailer script again and review the error messages and logs for more specific information about the issue. This should help you identify and resolve the SMTP connectivity problem.

ownwebservers1

The error suggests PHP's `fsockopen` is blocked or restricted. Check firewall rules, ensure port 25 is open in PHP config, and verify your hosting allows outbound SMTP connections.


WordPress Hosting