PHPMailer Pro Examples

All of the links at the left are examples designed to show how to send emails using PHPMailer Pro version 2024.1.3.0 or higher . The advanced tests fully use Exception Handling and provide in-depth error messages.

Sendmail, Basic Test

Demonstrates how to a send an email using Sendmail as email transport.

<html>
<head>
<title>PHPMailer Pro - Sendmail basic test</title>
</head>
<body>
<?php
/*
 * This test designed for PHPMailer Pro version 2024.1.2.1 and up ...
 */
// There are a number of ways to test your scripts. One of those is
// aboutmy.email test service ...
// if you prefer NOT to use a test service, please change
// the email addresses as you would like them to be for your tests

require_once('assets/lib/PHPMailer.Pro.php');
class_alias("codeworxtech\PHPMailerPro\PHPMailerPro", "PHPMailerPro");

$mail = new PHPMailerPro();

$recipient = ['recipient@example.com'=>'Recipient Name'];
$sender    = ['sender@example.net'=>'Sender Name'];

$mail->SetSender($sender);
$mail->AddRecipient($recipient);
$mail->subject     = "PHPMailer Pro basic sendmail test";
$mail->messageText = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->messageHTML = "contents.html";
$mail->AddAttachment("images/at_public_domain.png"); // attachment
$mail->AddAttachment("images/PHPMailerPro_mini.png");   // attachment

if ($mail->Send('sendmail')) { //choose sendmail as transport method, defaults to smtp if left empty
  echo "Email sent successfully.<br>";
} else {
  echo "Oops! Error sending email.<br>";
}

?>
</body>
</html>
Download example