剛試出來的一個小範例,使用Zend Framework所提供的Zend_Mail來寄信~
而所指定的SMTP就是要透過Google的Gmail來寄信~
在使用這個範例之前~ 由於Gmail必須透過加密傳輸~ 所以請確認你已經為PHP安置好OpenSSL
程式範例如下:
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$config = array(
'auth' => 'login',
'username' => '你的帳號',
'password' => '******',
'ssl' => 'tls',
'port' => '587'
);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail('UTF-8');
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('[email protected]', 'Some Sender');
$mail->addTo('[email protected]', 'Shen');
$mail->setSubject('Zend Mail!');
$mail->send($transport);
參考資源:
Zend_Mail - how to use Zend_Mail_Transport_Smtp for googlemail.com
