9951 explained code solutions for 126 technologies


phpmailerHow do I manually install PHPMailer?


  1. Download the latest version of PHPMailer from here.
  2. Extract the zip file and copy the src directory into your project.
  3. Include the autoload.php file in your project:
require 'src/PHPMailer/src/PHPMailerAutoload.php';
  1. Create a new PHPMailer instance:
$mail = new PHPMailer;
  1. Configure the mailer settings as needed, for example:
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
  1. Set the message details:
$mail->setFrom('[email protected]', 'Sender');
$mail->addAddress('[email protected]', 'Recipient');
$mail->Subject = 'PHPMailer Test';
$mail->Body = 'This is a test message from PHPMailer.';
  1. Send the message:
if (!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent.';
}

Output example

Message has been sent.

Edit this code on GitHub