◀ Back to examples

Basic Example

This demonstrates sending out one email messages with multipart/alternative support with Exception Handling.

With the exception of SMTP examples, PHPMailer Pro will automatically detect the MTA (Mail Transfer Agent). There is no requirement to add properties for IsQmail, IsSendmail, or IsMail. The properties are deprecated and will be removed in a future release.

<?php

require('assets/phpmailer2/PHPMailer Pro.php');

$mail = new codeworxtech\PHPMailer Pro();

try {

  $mail->SetSender( ["name@yourdomain.com" => "First Last" ] );

  $mail->AddRecipient( ["whoto@otherdomain.com" => "John Doe" ] );

  $mail->Subject     = "PHPMailer Pro Test Subject via sendmail, basic";

  $mail->MessageHTML = "data/contents.html";
  $mail->MessageText = "To view the message, please use an HTML compatible email viewer!";

  if ($mail->Send()) {
    echo 'Message has been sent.';
  }
} catch (Exception $e) {
  echo $e->errorMessage();
}

?>
Download example