Swift Mailer 發送郵件

1 下載組件php

$ composer require "swiftmailer/swiftmailer:^6.0"

 

2 利用php進行發送swift

   第一種方法利用smtp服務器

require_once '/path/to/vendor/autoload.php';

// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.example.org', 25))
  ->setUsername('your username')
  ->setPassword('your password')
;

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = (new Swift_Message('Wonderful Subject'))
  ->setFrom(['john@doe.com'])
  ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);

 

第二種方法利用sendmail本地發送,前提是你的服務器已經安裝好sendmail組件composer

 

// Sendmail
$transport = new Swift_SendmailTransport('/usr/sbin/sendmail -bs');
相關文章
相關標籤/搜索