Skip to content

Instantly share code, notes, and snippets.

@amariliscamargo
Forked from michaelwhyte/composer.json
Created February 23, 2022 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amariliscamargo/c41cdbff4f34af015c66ee86672f6426 to your computer and use it in GitHub Desktop.
Save amariliscamargo/c41cdbff4f34af015c66ee86672f6426 to your computer and use it in GitHub Desktop.
mail.php - phpmailer + mailhog - send mail via smtp
{
"require": {
"phpmailer/phpmailer": "^5.2"
}
}
<?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