Created
March 15, 2019 03:14
-
-
Save darkcolonist/de56856b7584133f15e867a586e97696 to your computer and use it in GitHub Desktop.
sendmail template for Swift-5.4.0
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 | |
header("Content-type: text/plain"); | |
require_once('vendor/autoload.php'); | |
$config = array( | |
// "host" => "siteurl.com", | |
"host" => "localhost", | |
"sender" => "[email protected]", // CHANGE ME | |
"sender_name" => "My New Site to send Messages!", | |
"password" => "CHANGEMEPLS", // CHANGE ME | |
"message" => "hello there, i am trying something new!", | |
// "port" => 465, | |
"port" => 25, | |
"recipients" => array( | |
"[email protected]" // CHANGE ME | |
) | |
); | |
$transport = Swift_SmtpTransport::newInstance($config["host"], $config["port"]) | |
->setUsername($config["sender"]) | |
->setPassword($config["password"]) | |
; | |
$body = $config["message"]; | |
$mailer = new Swift_Mailer($transport); | |
$message = (new Swift_Message("message from ".$config["host"])) | |
->setFrom([$config["sender"] => $config["sender_name"]]) | |
->setTo($config["recipients"]) | |
->setBody($body, 'text/html') | |
; | |
try{ | |
$results = array(); | |
$result = $mailer->send($message, $errors); | |
if(!$result) { | |
$results['error'] = 1; | |
$results['message'] = 'Error: message not sent'; | |
} else { | |
$results['error'] = 0; | |
$results['message'] = 'Success: message was sent'; | |
} | |
$mailer->getTransport()->stop(); | |
} catch (\Swift_TransportException $e) { | |
die(var_dump($e)); | |
} catch (Exception $e) { | |
die(var_dump($e)); | |
} | |
echo "results:"; | |
var_dump($results); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to find out swift version
