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.
SMTP, Basic Test, copy email to Sent mailbox
Demonstrates how to a send an email using SMTP as email transport with a copy of the email sent to the Sender's Sent Mailbox.
<html>
<head>
<title>PHPMailer Pro - SMTP basic test with authentication</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->AddReplyTo($sender);
$mail->AddRecipient($recipient);
$mail->subject = "PHPMailer Pro basic SMTP test";
$mail->messageText = "To view the message, please use an HTML compatible email viewer!"; // optional - MsgHTML will create an alternate automatically
$mail->messageHTML = "contents.html";
$mail->AddAttachment("images/at_public_domain.png"); // attachment
$mail->AddAttachment("images/PHPMailerPro_mini.png"); // attachment
$mail->smtpHost = "mail.example.net"; // SMTP server
$mail->smtpDebug = 1; // enables SMTP debug information (for testing)
// $mail->smtpPort = 587; // optional (desired, but not needed) set the SMTP port for the SMTP server
$mail->smtpUsername = "sender@example.net"; // SMTP account username
$mail->smtpPassword = "***password***"; // SMTP account password
$mail->imapAddToSent = true;
$mail->imapHost = "mail.example.net";
$mail->imapUsername = "sender@example.net";
$mail->imapPassword = "***password***";
if ($mail->Send('smtp')) { //choose SMTP as transport method
echo "Email sent successfully.<br>";
} else {
echo "Oops! Error sending email.<br>";
}
?>
</body>
</html>
Download example