-
-
Save michaelwhyte/2d2048c6fcaf4a82cd8bc5a844ec4dc8 to your computer and use it in GitHub Desktop.
mail.php - phpmailer + mailhog - send mail via smtp
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
{ | |
"require": { | |
"phpmailer/phpmailer": "^5.2" | |
} | |
} |
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 | |
require 'vendor/autoload.php'; | |
$mail = new PHPMailer; | |
// $mail->SMTPDebug = 3; | |
$mail->isSMTP(); | |
$mail->Host = 'localhost'; | |
$mail->SMTPAuth = false; | |
$mail->Port = 1025; | |
$mail->setFrom('[email protected]', 'Mailer'); | |
$mail->addAddress('[email protected]', 'Joe User'); | |
$mail->addAddress('[email protected]'); | |
$mail->addReplyTo('[email protected]', 'Information'); | |
$mail->addCC('[email protected]'); | |
$mail->addBCC('[email protected]'); | |
$mail->addAttachment('/tmp/file.tar.gz'); | |
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); | |
$mail->isHTML(true); | |
$mail->Subject = 'Here is the subject'; | |
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; | |
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; | |
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