1 頁 (共 1 頁)

php mail() 的相關設定

發表於 : 2022-07-08, 15:43
dtchang
1. 使用: fake sendmail for bugzilla/windows
安裝於: c:/wamp/sendmail
需設定 senmail.ini (含error log)
中華大學主機相關設定: 不使用ssl

代碼: 選擇全部

smtp_server=mail.chu.edu.tw

; smtp port (normally 25)

smtp_port=25

; SMTPS (SSL) support
;   auto = use SSL for port 465, otherwise try to use TLS
;   ssl  = alway use SSL
;   tls  = always use TLS
;   none = never try to use SSL

smtp_ssl=none
; 需提供
auth_username=xxxx@chu.edu.tw
auth_password=xxxx

2. php.ini 設定

代碼: 選擇全部

[mail function]
; For Win32 only.
smtp_server=mail.chu.edu.tw
smtp_port = 25
auth_username =xxxx@chu.edu.tw
auth_password =xxxx

sendmail_from =xxxx@chu.edu.tw

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

mail.add_x_header = On

3. 測試信件

代碼: 選擇全部

<?php
  $to =" dtchang0322@gmail.com "; //收件者
  $subject = "test"; //信件標題
  $msg = "smtp發信測試 ".date("Y-m-d H:i:s");//信件內容
  $headers = "From: dtchang@chu.edu.tw"; //寄件者
  
  echo date("Y/m/d H:i:s"); echo "\n";
  if(mail("$to", "$subject", "$msg", "$headers")):
   echo "信件已經發送成功。";//寄信成功就會顯示的提示訊息
  else:
   echo "信件發送失敗!\n";//寄信失敗顯示的錯誤訊息
   $errorMessage = error_get_last()['message'];
   echo "error message:".$errorMessage;
  endif;
?>