2014/12/29

CentOS 6.5 Postfix 加入DNS 並利用WWW發送郵件


郵件正解如下:
$TTL 86400
@   IN  SOA     dns.cy.local. root.cy.local. (
        0 ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)

@       IN      NS      dns.cy.local.
@       IN      A       192.168.10.13
@       IN      MX 10   mail.cy.local.
dns     IN      A       192.168.10.13
mail    IN      A       192.168.10.15
web     IN      A       192.168.10.16
www     IN      CNAME   web




反解:
$TTL 86400
@   IN  SOA     dns.cy.local. root.cy.local. (
        0  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)

@       IN      NS      dns.cy.local.
@       IN      PTR     cy.local.
dns      IN      A       192.168.10.13
mail    IN      A       192.168.10.15
web     IN      A       192.168.10.16
13      IN      PTR     dns.cy.local.
15      IN      PTR     mail.cy.local.
16      IN      PTR     web.cy.local.



接著修改postfix,完成後記得重啟
vim /etc/postfix/main.cf


myhostname = mail.cy.local 
mydomain = cy.local
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain


接著到Web伺服器,建立一個index.html以及test.php
index.html內容如下:
<!DOCTYPE html>
<html>
<head>
 <title></title>
</head>
<body>
 <form method="post" action="test.php">
  <input type="email" name="to"><br/>
 
  <input type="text" name="msg"><br/>
 
  <input type="submit" value="送出信件">
 </form>
</body>
</html>

test.php如下:
<?php
 $to = $_POST["to"];
 $msg = $_POST["msg"];
 $subject = 'Hi root';
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=utf8' . "\r\n";
 $headers .= 'From: cy@mail.cy.local';
 
 if(mail($to, $subject, $msg, $headers)){
  echo "恭喜你寄信成功";
 }else{
  echo "寄信失敗,請確認使用者是否存在";
 }
?>


執行結果:






參考資料:
http://ostechnix.wordpress.com/2013/02/08/setup-mail-server-using-postfixdovecotsquirrelmail-in-centosrhelscientific-linux-6-3-step-by-step/
CentOS 6.5 用Postfix架設Mail Server並使用PHP寄信
CentOS DNS新增WWW伺服器