Created
October 30, 2024 16:09
-
-
Save waynegraham/1d168c4fd789dc7b591225f7c91c3cef to your computer and use it in GitHub Desktop.
PHP Mailer Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use PHPMailer\PHPMailer\PHPMailer; | |
use PHPMailer\PHPMailer\SMTP; | |
use PHPMailer\PHPMailer\Exception; | |
require './vendor/autoload.php'; | |
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/'); | |
$dotenv->load(); | |
$mail = new PHPMailer(true); | |
$mail->isSMTP(); | |
$mail->Host = "smtp.office365.com"; | |
$mail->SMTPAuth = true; | |
$mail->Username = $_ENV['SMTP_USER']; | |
$mail->Password = $_ENV['SMTP_PASSWORD']; | |
$mail->SMTPSecure = 'tls'; | |
$mail->Port = 587; | |
$mail->setFrom('[email protected]'); | |
$mail->addAddress('[email protected]'); | |
$mail->Subject = 'Test email using PHPMailer'; | |
$mail->isHTML(true); | |
$mailContent = "<h1>Send HTML Email using SMTP in PHP</h1> | |
<p>This is a test email I’m sending using SMTP mail server with PHPMailer.</p>"; | |
$mail->Body = $mailContent; | |
if(!$mail->send()){ | |
echo 'Message could not be sent.'; | |
echo 'Mailer Error: ' . $mail->ErrorInfo; | |
}else{ | |
echo 'Message has been sent'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment