PHP的mail()函數可以實現直接用腳本發送郵件。
用mail()函數發送郵件之前,首先需要在檔案裏面設定一下郵件服務屬性,主要的`設定選項如下:
屬性 缺省值 說明 Changeable
SMTP “localhost” 只適用於Windows: SMTP服務器的 DNS 名或者 IP位址 PHP_INI_ALL
smtp_port “25″ 只適用於Windows: SMTP 端口號 PHP_INI_ALL
sendmail_from NULL 只適用於Windows: 指定要發送郵件的From地址 PHP_INI_ALL
sendmail_path NULL 只適用於Unix: 指定發送郵件的程序路徑 PHP_INI_SYSTEM
如下代碼實現了一個簡單的發送郵件例子:
$to = ”;
$subject = “歡迎來到IT公司面試手冊”;
$message = “Hello! 歡迎來到IT公司面試手冊.”;
$from = ”;
$headers = “From: $from”;
mail($to,$subject,$message,$headers);
echo “Mail Sent.”;
?>