Last active
March 28, 2018 17:55
-
-
Save fedir/4928d56c5b9ef36ea29d to your computer and use it in GitHub Desktop.
Test send mail with PHP in Shell
This file contains hidden or 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 | |
| // ## 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; |
This file contains hidden or 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 -r '$headers="From: [email protected]"; mail("[email protected]", "Test email from Shell", "Test message", $headers);' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helps to check if PHP could send the mail from Your website.