QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3526|回复: 1

Debian Exim4 與 PHP mail() 配置教學

[复制链接]
发表于 2006-12-10 21:55:46 | 显示全部楼层 |阅读模式
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]
 楼主| 发表于 2006-12-10 22:38:10 | 显示全部楼层
我也把這篇分享到外部好了  

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

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




original from php.net
smtp.php
[code:1]
<?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;
}

?>
[/code:1]

config.php

[code:1]

<?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','');
?>
[/code:1]
但是其實 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/
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-5-6 02:40 , Processed in 0.276530 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表