How do I test SMTP email sending with PHPMailer?

Последна промяна: 15.10.2025 09:03

To test SMTP email sending using PHPMailer, follow these steps over SSH:

  1. Download PHPMailer:
    wget https://github.com/PHPMailer/PHPMailer/archive/master.zip
    unzip master.zip
    mv PHPMailer-master PHPMailer
  2. Create a test.php file in the same directory with the following code, updating the settings with your email credentials:
SMTPDebug = SMTP::DEBUG_SERVER;
 $mail->isSMTP();
 $mail->Host = 'mail.kiirahosting.com';
 $mail->SMTPAuth = true;
 $mail->SMTPSecure = "ssl";
 $mail->Port = 465;
 $mail->Username = 'websitetest@nilevillagehotel.com';
 $mail->Password = 'Muw0gg0@2021';

 $mail->setFrom('websitetest@nilevillagehotel.com', 'Sender Name');
 $mail->addAddress('nilevillagehotelspa@gmail.com', 'Receiver Name');
 $mail->addReplyTo('websitetest@nilevillagehotel.com', 'Sender Name');

 $mail->IsHTML(true);
 $mail->Subject = "Test Email via SMTP and PHPMailer";
 $mail->Body = 'This is an HTML test email.';
 $mail->AltBody = 'Plain text test email for non-HTML clients.';

 $mail->send();
 echo "Email sent successfully.";
} catch (Exception $e) {
 echo "Email sending failed. Error: {$mail->ErrorInfo}";
}
?>

Run the script to test. Ensure your credentials and server settings are correct.