PHPMailer won't just work!

I don’t understand why my PHPMailer script (very basic) won’t run. The script is from this PHPMailer tutorial.
Please if there is another tutorial that works for you, I will be very glad if you can refer me to it!

What error are you getting?

Can you post your code here and remove any private information (smtp server, username, password, et al)

I am trying to run this on my GoDaddy account which is not SSL certified.
Hoping I haven’t left any other info out!

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
require 'PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug   = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host        = "localhost";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port        = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth    = true;
//Username to use for SMTP authentication
$mail->Username    = "";
//Password to use for SMTP authentication
$mail->Password    = "my-long-password";
//$mail->SMTPSecure  = 'ssl';
//Set who the message is to be sent from
$mail->setFrom('', 'First Last');
//Set an alternative reply-to address
//$mail->addReplyTo('', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('', 'Person');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';

$mail->Body = '<h1>Hello, this is my message.</h1> Did you know??';
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";


Debug Message:
SMTP ERROR: Failed to connect to server: Connection refused (111)

SMTP connect() failed.

Mailer Error: SMTP connect() failed.

Seems to indicate that SMTPAuth should be set to false, and you should not set a Username or Password.

If I recall, GoDaddy blocks port 25 from its virtual private servers / shared environments as an attempted measure against inadvertently hosting spam factories.

some times will get error like this - but we can fix it by changing IP.

Changing what IP? The mail server? If so, that may make a bit of sense, but if you are referring to the server the script is hosted on, that only applies if they block your IP via iptables and you are contacting a mail server on a different IP address

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.