PHPMailer Lite Examples
All of the links at the left are examples designed to show how to send emails using PHPMailer Lite version 2024.1.2.1 or higher. The advanced tests fully use Exception Handling and provide in-depth error messages.
SMTP, Basic Test, Un-Authenticated
Demonstrates how to a send an email using SMTP as email transport un-authenticated.
<html>
<head>
<title>PHPMailer Lite - SMTP basic test with no authentication</title>
</head>
<body>
<?php
/*
* This test designed for PHPMailer Lite 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.Lite.php');
class_alias("codeworxtech\PHPMailerLite\PHPMailerLite", "PHPMailerLite");
$mail = new PHPMailerLite();
$recipient = ['recipient@example.com'=>'Recipient Name'];
$sender = ['sender@example.net'=>'Sender Name'];
$mail->SetSender($sender);
$mail->AddReplyTo($sender);
$mail->AddRecipient($recipient);
$mail->subject = "PHPMailer Lite SMTP basic with no authentication";
$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/PHPMailerLite_mini.png"); // attachment
$mail->AddAttachment("images/PHPMailerLite_square.png");// attachment
$mail->SMTPDebug = 2; // NOTE: HAS NO EFFECT FOR UN-AUTHENTICATED SMTP
if ($mail->Send('smtp')) {
echo "Email sent successfully.<br>";
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
</body>
</html>
Download example