1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| # 取得 SMTP 資料 1. My Account > Mailgun Subdomains 2. Sandbox Name > YOUR_DOMAIN 3. SMTP Authentication
# 設定 SMTP 資料 <?php $config = array( 'mail' => array( 'subject' => 'SUBJECT_NAME', 'from_mail' => 'no-reply@YOUR_DOMAIN', 'from_name' => 'No Reply' ), 'smtp' => array( 'host' => 'smtp.mailgun.org', 'port' => 465, 'username' => 'SMTP_USERNAME', 'password' => 'SMTP_PASSWORD', 'security' => 'ssl' ) );
# 發送郵件 (通過 Swift) <?php // 發送電郵 Swift_Mailer::newInstance( // 傳送方式為 SMTP Swift_SmtpTransport::newInstance( $config['smtp']['host'], $config['smtp']['port'], $config['smtp']['security'] )->setUsername($config['smtp']['username'])->setPassword($config['smtp']['password']) )->send( // 傳送內容 Swift_Message::newInstance()->setSubject($config['mail']['subject'])->setFrom(array( $config['mail']['from_mail'] => $config['mail']['from_name'] ))->setTo(array( "YOUR_EMAIL_ADDRESS" => 'YOUR_NAME' ))->setBody($email_template, 'text/html') );
|