views:

447

answers:

1

Hi There,

I've used PHPMailer on several projects but now I'm stuck. It gives me the error:
SMTP Error: Could not connect to SMTP host.
I've tried sending email from Thunderbird and it works ! But not through PHPMailer ... Here are the settings from Thunderbird:

Server name: mail.exampleserver.com
Port: 587
Username: [email protected]
Secure Authentication: No
Connection Security: STARTTLS

I've compared these with the server at my last project where I used PHPMailer and they were:

Server name: mail.exampleserver2.com
Port: 465
Username: [email protected]
Secure Authentication: No
Connection Security: SSL/TLS

My php code is:

 $mail = new PHPMailer();
 $mail->IsSMTP(); // send via SMTP
 $mail->Host = SMTP_HOST; // SMTP servers
 $mail->Port = SMTP_PORT; // SMTP servers
 $mail->SMTPAuth = true; // turn on SMTP authentication
 $mail->Username = SMTP_USER; // SMTP username
 $mail->Password = SMTP_PASSWORD; // SMTP password
 $mail->From = MAIL_SYSTEM;
 $mail->FromName = MAIL_SYSTEM_NAME;
 $mail->AddAddress($aSecuredGetRequest['email']);
 $mail->IsHTML(true); // send as HTML

Where I am wrong?

A: 

Your problem is most likely this

Connection Security: STARTTLS Connection Security: SSL/TLS

Those are 2 different protocols, are you using the correct one, whatever one you're using in Thunderbird needs to be used.

Try setting the variable:

// if you're using SSL
$mail->SMTPSecure = 'ssl';
// OR use TLS
$mail->SMTPSecure = 'tls';
Viper_Sb