Skip to content

Instantly share code, notes, and snippets.

@fedir
Last active March 28, 2018 17:55
Show Gist options
  • Select an option

  • Save fedir/4928d56c5b9ef36ea29d to your computer and use it in GitHub Desktop.

Select an option

Save fedir/4928d56c5b9ef36ea29d to your computer and use it in GitHub Desktop.
Test send mail with PHP in Shell
<?php
// ## Requirements
//
// curl -sS https://getcomposer.org/installer | php
// mv composer.phar /usr/local/bin/composer
// composer require phpmailer/phpmailer
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->Port = 25; // TCP port to connect to
# $mail->SMTPAuth = true; // Enable SMTP authentication
# $mail->Username = ''; // SMTP username
# $mail->Password = ''; // SMTP password
# $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->setFrom('FROM@EMAIL', 'Serveur de test');
$mail->addAddress('TO@EMAIL', 'NAME'); // Add a recipient
$mail->addBCC('TOBCC@EMAIL');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Email test from server";
$mail->Body = "Lorem ipsum";
$mail->AltBody = "Lorem ipsum";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo PHP_EOL;
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
echo PHP_EOL;
php -r '$headers="From: [email protected]"; mail("[email protected]", "Test email from Shell", "Test message", $headers);'
@fedir
Copy link
Author

fedir commented Feb 23, 2015

Helps to check if PHP could send the mail from Your website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment