Phpmailer problem

Hello i have a problem witth php mailer my navigator display me always this error"SMTP connect() failed."
and this s my code

<?php
 
require_once("class.phpmailer.php");
require_once("class.smtp.php");
 
$mail = new PHPMailer;
  
//Enable SMTP debugging.
$mail->SMTPDebug = 3;                              
//Set PHPMailer to use SMTP.
$mail->isSMTP();           
//Set SMTP host name                         
$mail->Host = "smtp.xxxxxx";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;                         
//Provide username and password    
$mail->Username = "xxxxxx";                
$mail->Password = "xxxx";                          
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "ssl";                          
//Set TCP port to connect to
$mail->Port = 25;      //587    //80                        
  
$mail->From ="xxxxxx"; //from mailer
$mail->FromName = "test sender"; //mailer name
  
$mail->addAddress("xxxxxx", "Recepient Name");
  
$mail->isHTML(true);
  
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
  
if($mail->send()){
    echo "sent";
}
else{
    echo "sorry";
}

?>

I don’t know if you testing this out on a local server or not, but trying something like the following might help.

if (filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_URL) == "localhost") {
  $mail->isSmtp(); // Local Host:
  $mail->Port = EMAIL_PORT; // Local Host Port: (Usually 587)
} else {
  $mail->isSendMail(); // Remote Host:
}

the rest of the code that you have with except of the port and isSmtp();

Try to add

$mail->SMTPDebug = 2;

to get more details about the error

hello thanks foe the reply now i have this error ‘Mailer Error: Extension missing: openssl’
and the extension openssl.dll in php.in without ;

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