cnhnln 发表于 2006-12-10 21:55:46

Debian Exim4 與 PHP mail() 配置教學

http://eoffice.im.fju.edu.tw/phpbb/viewtopic.php?t=2682&view=previous&sid=6fc756287772213cc7c897aeb49259e6

測試環境:
Windows XP + Apache 2.0 + PHP 5.0

PHP相關設定(php.ini):
SMTP = %一架Debian Server%

修改部分:
Mail()的寫法,mail函式的第四個參數header裡
From:魏達特<[email protected]>
要改成
From:[email protected]



假如直接在該Debian Server上:
Debian(Sarge) Testing + Apache 2.0 + PHP 5.0 + exim4

PHP相關設定(php.ini):
sendmail_path = sendmail -t
說明:
sendmail_path預設會帶有參數 -t -i
-i會造成Exim持續等待輸入,而無法偵測文件傳送完畢,必須手動去掉此參數

Mail函式部分:
就目前測試,From依然可以寫成
From:魏達特<[email protected]>
的格式,只是中文會出現亂碼,目前仍無法克服


--------------------------------------------------------------------
希望這篇文章會對Exim4+PHP(mail)設定上有問題的人提供一些幫助

______________________________________________


朝著二十萬邁進吧!!
MSN: [email protected]

cnhnln 发表于 2006-12-10 22:38:10

我也把這篇分享到外部好了

利用自己的 Mail 函式直接透過 smtp 認證寄信的方法

程式碼是從 php.net 上修改來的




original from php.net
smtp.php

<?php
require_once('config.php');
function another_mail($to,$subject,$headers,$message)
{
list($me,$mydomain) = split("@",MAIL_FROM); // 很帥氣的 split 方法
// Now look up the mail exchangers for the recipient
list($user,$domain) = split("@",$to,2);


// Open an SMTP connection
$connection = fsockopen ('MAIL_SERVER', 25, &$errno, &$errstr, 1);
if (!$connection)
   return false;
$res=fgets($connection,256);
if(substr($res,0,3) != "220") return false;

// Introduce ourselves
fputs($connection, "EHLO\r\n");
while(strstr($res,'250 OK') == false)
{
      $res=fgets($connection,256);
};
if(substr($res,0,3) != "250") return false;

fputs($connection, "AUTH LOGIN\r\n"); // 以 login 方式作 auth
$res=fgets($connection,256);
if(substr($res,0,3) != "334") return false;


fputs($connection, base64_encode($me)."\r\n"); // $me 為 account
$res=fgets($connection,256);
if(substr($res,0,3) != "334") return false;

fputs($connection, base64_encode(SMTP_PASS)."\r\n"); // 到此 auth 完成
$res=fgets($connection,256);
if(substr($res,0,3) != "235") return false;

// Envelope from
fputs($connection, "MAIL FROM: $me\r\n");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") return false;

// Envelope to
fputs($connection, "RCPT TO: $to\r\n");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") return false;

// The message
fputs($connection, "DATA\r\n");
$res=fgets($connection,256);
if(substr($res,0,3) != "354") return false;

// Send To:, From:, Subject:, other headers, blank line, message, and finish
// with a period on its own line.
fputs($connection, "To: $to\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$res=fgets($connection,256);
if(substr($res,0,3) != "250") return false;

// Say bye bye
fputs($connection,"QUIT\r\n");
$res=fgets($connection,256);
if(substr($res,0,3) != "221") return false;
fclose ($connection);
return true;
}

?>


config.php



<?php
define('MYSQL_HOST', 'myhost');
define('MYSQL_USER', '');
define('MYSQL_PASS', '');
define('MYSQL_DBNAME', 'dbname');
define('MAIL_SERVER', 'blah.blah.blah');
define('MAIL_FROM','[email protected]'); // 寄件者
define('SMTP_PASS','');
?>

但是其實 pear 一定有已經寫好的函式可用
http://pear.php.net/reference/Mail-1.0.2/Mail/Mail_smtp.html
______________________________________________

copyleft◎utcr.org

copyleft◎ubuntu.org.tw

http://www.utcr.org/

http://pcmanx.csie.net/

http://www.debian.org.tw/

http://www.ubuntu.org.tw/
页: [1]
查看完整版本: Debian Exim4 與 PHP mail() 配置教學