Skip to content

Instantly share code, notes, and snippets.

@michaelwhyte
Forked from rogeriopradoj/composer.json
Created August 3, 2018 16:12
Show Gist options
  • Save michaelwhyte/2d2048c6fcaf4a82cd8bc5a844ec4dc8 to your computer and use it in GitHub Desktop.
Save michaelwhyte/2d2048c6fcaf4a82cd8bc5a844ec4dc8 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('[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