Created
February 22, 2021 22:17
-
-
Save gusLopezC/4b04b52bb1ae920709a718dede9d76c7 to your computer and use it in GitHub Desktop.
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
<?php | |
use PHPMailer\PHPMailer\PHPMailer; | |
use PHPMailer\PHPMailer\Exception; | |
require 'vendor/phpmailer/phpmailer/src/Exception.php'; | |
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php'; | |
require 'vendor/phpmailer/phpmailer/src/SMTP.php'; | |
$mail = new PHPMailer(); | |
$mail->isSMTP(); | |
$mail->Host = "smtp.mailtrap.io";; | |
$mail->SMTPAuth = true; | |
$mail->Username = 'b8e38a65bd5b4d'; //paste one generated by Mailtrap | |
$mail->Password = "7983c53d5c7276"; //paste one generated by Mailtrap | |
$mail->SMTPSecure = 'tls'; | |
$mail->Port = 2525; | |
$mail->setFrom('info@mailtrap.io', 'Mailtrap'); | |
$mail->addReplyTo('info@mailtrap.io', 'Mailtrap'); | |
$mail->addAddress('recipient1@mailtrap.io', 'Tim'); | |
$mail->addCC('cc1@example.com', 'Elena'); | |
$mail->addBCC('bcc1@example.com', 'Alex'); | |
$mail->Subject = 'Test Email via Mailtrap SMTP 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; | |
$mail->SMTPOptions = [ | |
'ssl' => [ | |
'verify_peer' => false, | |
'verify_peer_name' => false, | |
'allow_self_signed' => true, | |
] | |
]; | |
if ($mail->send()) { | |
echo 'Message has been sent'; | |
} else { | |
echo 'Message could not be sent.'; | |
echo 'Mailer Error: ' . $mail->ErrorInfo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment