PHPMailer: “impossible de se connecter à l'hôte SMTP”

$email_message = "Form details below.\n\n";

function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
}

$email_message .= "Full Name: ".clean_string($_POST['full_name'])."\n";
$email_message .= "Email: ".clean_string($_POST['email'])."\n";
$email_message .= "Telephone number: ".clean_string($_POST['telephone'])."\n";
$email_message .= "Message: ".clean_string($_POST['comments'])."\n";


$mail             = new PHPMailer();
$body             = $email_message;
$body             = str_replace('\\', '', $body);

$mail->IsSMTP(); //telling the class to use SMTP
$mail->SMTPAuth   = true;             //enable SMTP authentication
$mail->SMTPSecure = "ssl";            //sets the prefix to the servier
$mail->Host       = "smtp.gmail.com"; //sets GMAIL as the SMTP server
$mail->Port       = 465;              //set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]";  //GMAIL username
$mail->Password   = "XXXXXX";         //GMAIL password

$mail->SetFrom('[email protected]', 'First Last');

$mail->Subject    = "Imperia";

$mail->AltBody    =                   //optional, comment out and test
    "To view the message, please use an HTML compatible email viewer!";

$mail->MsgHTML($body);

$address = "[email protected]";
$mail->AddAddress($address, "To Name");

if(!$mail->Send()) {

    echo "<font color='red'> Message error </font>". $mail->ErrorInfo;
} else {
    echo "<font color='red'> Message sent </font>";
} 

Je suis en utilisant ce code pour essayer d'envoyer un email à l'aide de SMTP, mais j'ai une erreur:

SMTP Error: could not connect to SMTP hôte

Quelqu'un pourrait-il me dire quel est le problème ici? Je ne peux pas trouver un moyen de résoudre ce problème. Grâce

  • activer le débogage $mail->SMTPDebug = 1; pour plus de détails
InformationsquelleAutor fish40 | 2012-05-16