Swift Mailer官方摘要

Introduction

Swift Mailer is a component-based library for sending e-mails from PHP applications.

Install

The preferred way to install Swiftmailer is via Composer:
<pre>
$ composer require swiftmailer/swiftmailer
</pre>

Create and send Message

<pre>

require_once 'lib/swift_required.php';
//get a transport instance
//include smtp server port
//username
//password 
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)    
->setUsername('your username')    
->setPassword('your password');

//get a Mailer instance by your config
$mailer = Swift_Mailer::newInstance($transport);

//builde a message
$message = Swift_Message::newInstance()
// Give the message a subject 
  ->setSubject('Your subject') 
// Set the From address with an associative array 
  ->setFrom(array('john@doe.com' => 'John Doe')) 
// Set the To addresses with an associative array 
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name')) 
// Give it a body 
  ->setBody('Here is the message itself') 
// And optionally an alternative body 
  ->addPart('<q>Here is the message itself</q>', 'text/html') 
// Optionally add any attachments 
  ->attach(Swift_Attachment::fromPath('my-document.pdf')) ;

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

</pre>

下面的可以不看


Including Swift Mailer (Autoloading)

If you are using Composer, Swift Mailer will be automatically autoloaded.
If not, you can use the built-in autoloader by requiring the swift_required.php
<pre>
<code>
require_once '/path/to/swift-mailer/lib/swift_required.php';
</code>
</pre>
If you want to override the default Swift Mailer configuration, call the init() method on the Swift
class and pass it a valid PHP callable (a PHP function name, a PHP 5.3 anonymous function, ...):

<pre>

require_once '/path/to/swift-mailer/lib/swift_required.php';

function swiftmailer_configurator() { 
    // configure Swift Mailer 
    Swift_DependencyContainer::getInstance()->... 
    Swift_Preferences::getInstance()->...
}

Swift::init('swiftmailer_configurator');

</pre>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末焚虱,一起剝皮案震驚了整個濱河市箫老,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌垦巴,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,331評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件哥牍,死亡現(xiàn)場離奇詭異谐檀,居然都是意外死亡,警方通過查閱死者的電腦和手機等脂,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,372評論 3 398
  • 文/潘曉璐 我一進店門俏蛮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人慎菲,你說我怎么就攤上這事嫁蛇。” “怎么了露该?”我有些...
    開封第一講書人閱讀 167,755評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長解幼。 經常有香客問我抑党,道長,這世上最難降的妖魔是什么撵摆? 我笑而不...
    開封第一講書人閱讀 59,528評論 1 296
  • 正文 為了忘掉前任底靠,我火速辦了婚禮,結果婚禮上特铝,老公的妹妹穿的比我還像新娘暑中。我一直安慰自己壹瘟,他們只是感情好,可當我...
    茶點故事閱讀 68,526評論 6 397
  • 文/花漫 我一把揭開白布鳄逾。 她就那樣靜靜地躺著稻轨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪雕凹。 梳的紋絲不亂的頭發(fā)上殴俱,一...
    開封第一講書人閱讀 52,166評論 1 308
  • 那天,我揣著相機與錄音枚抵,去河邊找鬼线欲。 笑死,一個胖子當著我的面吹牛汽摹,可吹牛的內容都是我干的李丰。 我是一名探鬼主播,決...
    沈念sama閱讀 40,768評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼竖慧,長吁一口氣:“原來是場噩夢啊……” “哼嫌套!你這毒婦竟也來了?” 一聲冷哼從身側響起圾旨,我...
    開封第一講書人閱讀 39,664評論 0 276
  • 序言:老撾萬榮一對情侶失蹤踱讨,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后砍的,有當地人在樹林里發(fā)現(xiàn)了一具尸體痹筛,經...
    沈念sama閱讀 46,205評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,290評論 3 340
  • 正文 我和宋清朗相戀三年廓鞠,在試婚紗的時候發(fā)現(xiàn)自己被綠了帚稠。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,435評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡床佳,死狀恐怖滋早,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情砌们,我是刑警寧澤杆麸,帶...
    沈念sama閱讀 36,126評論 5 349
  • 正文 年R本政府宣布,位于F島的核電站浪感,受9級特大地震影響昔头,放射性物質發(fā)生泄漏。R本人自食惡果不足惜影兽,卻給世界環(huán)境...
    茶點故事閱讀 41,804評論 3 333
  • 文/蒙蒙 一揭斧、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧峻堰,春花似錦讹开、人聲如沸盅视。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,276評論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽左冬。三九已至,卻和暖如春纸型,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背梅忌。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評論 1 272
  • 我被黑心中介騙來泰國打工狰腌, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人牧氮。 一個月前我還...
    沈念sama閱讀 48,818評論 3 376
  • 正文 我出身青樓琼腔,卻偏偏與公主長得像,于是被迫代替她去往敵國和親踱葛。 傳聞我的和親對象是個殘疾皇子丹莲,可洞房花燭夜當晚...
    茶點故事閱讀 45,442評論 2 359

推薦閱讀更多精彩內容