[Wacow] 使用Gmail SMTP發信

分類: 技術分享 作者: abu

13 八月 2009

嘗試在wacow framework,使用gmail smtp發信,不過怎麼設定都一直錯誤,

拜讀咕狗大神之後,發現必須使用ssl連線,

於是開始搜尋wacow controller裡面Mailer的來源,為了測試方便,就不做靈活的改寫,直接硬來,

找到 path\wacow\app\lib\Wacow\Mail\PHPMailer.php,加上

public function setGoogle(){
	$this->_mailer->SetLanguage("tw",'Wacow/vendor/PHPMailer//language/');
	$this->_mailer->Mailer = "smtp";
	$this->_mailer->CharSet = 'BIG5';
	$this->_mailer->ContentType = "text/html";
	$this->_mailer->Mailer = "smtp";
	$this->_mailer->CharSet = 'BIG5';
	$this->_mailer->ContentType = "text/html";
 
	$this->_mailer->SMTPAuth   = true;
	$this->_mailer->SMTPSecure = "ssl";
	$this->_mailer->Host       = "smtp.gmail.com";
	$this->_mailer->Port       = 465;                   
 
	$this->_mailer->Username   = "填上gmail帳號";
	$this->_mailer->Password   = "填上gmail密碼";
}

接著在path\wacow\app\base\Mailer.php的send函式裡面,找到『 $result = $this->_mailer->send(); 』,在他之前任意位置加上

$this->_mailer->setGoogle();

最後到controller測試一下,隨便找個action召喚Mailer出來

$mailer = new Mailer();
(略)
$mailer->send('咕狗SMTP測試', 'abu@wabow.com')

接著就會在信箱內看到剛寄發的mail,重點是PHPMailer提供的SMTPSecure屬性,要記得設為"ssl",不過好像要更新到XX版之後才有,測試報告結束。

我要留言

關於這裡

這個部落格分享了哇寶在電子商務領域的技術及資訊,希望能讓更多人一起為台灣的網路產業加油。