Skip to content

Instantly share code, notes, and snippets.

@LeoOnTheEarth
Last active September 1, 2022 06:09
Show Gist options
  • Save LeoOnTheEarth/e07d2764458d2486ab00e43f085edb1e to your computer and use it in GitHub Desktop.
Save LeoOnTheEarth/e07d2764458d2486ab00e43f085edb1e to your computer and use it in GitHub Desktop.
SwiftMailer 範例
<?php
// 需要先安裝 swiftmailer
// composer require "swiftmailer/swiftmailer:^6.0"
require __DIR__ . '/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('email-smtp.us-east-1.amazonaws.com', 587, 'tls'))
->setUsername('username')
->setPassword('password')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['gamehours@gamehours.com' => 'GameHours'])
->setTo(['leo.tsun@gamehours.com'])
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment