-
-
Save amariliscamargo/c41cdbff4f34af015c66ee86672f6426 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('from@example.com', 'Mailer'); | |
$mail->addAddress('joe@example.net', 'Joe User'); | |
$mail->addAddress('ellen@example.com'); | |
$mail->addReplyTo('info@example.com', 'Information'); | |
$mail->addCC('cc@example.com'); | |
$mail->addBCC('bcc@example.com'); | |
$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