[
[email protected]~/]# telnet localhost 25
trying 127.0.0.1...
connected to localhost.
escape character is '^]'.
220 server.domain.com.br esmtp postfix (2.1.0)
mail from:
[email protected] 250 ok
rcpt to:
[email protected] 250 ok
data
354 end data with <cr><lf>.<cr><lf>
teste
.
250 ok: queued as 7b41f4665a
quit
221 bye
connection closed by foreign host.
trying 127.0.0.1...
connected to localhost.
escape character is '^]'.
220 server.domain.com.br esmtp postfix (2.1.0)
<?php
require_once 'mail.php';
$conf['mail'] = array(
'host' => 'xx.xx.xx.xx', //smtp服務器地址,可以用ip地址或者域名
'auth' => true, //true表示smtp服務器需要驗證,false代碼不需要
'username' => 'tester', //用戶名
'password' => 'retset' //密碼
);
/***
* 使用$headers數組,可以定義郵件頭的內容,比如使用$headers['reply-to']可以定義回復地址
* 通過這種方式,可以很方便的定制待發送郵件的郵件頭
***/
$headers['from'] = '
[email protected]'; //發信地址
$headers['to'] = '
[email protected]'; //收信地址
$headers['subject'] = 'test mail send by php'; //郵件標題
$mail_object = &mail::factory('smtp', $conf['mail']);
$body = <<< msg //郵件正文
hello world!!!
msg;
$mail_res = $mail_object->send($headers['to'], $headers, $body); //發送
if( mail::iserror($mail_res) ){ //檢測錯誤
die($mail_res->getmessage());
}
?>