PHP 寄送電子郵件

來源:互聯網
上載者:User

標籤:meta   als   tab   參數   example   str   sla   code   font   

PHP mail() 函數
函數用於從指令碼中寄送電子郵件。

文法:
  mail(to,subject,message,headers,parameters)

 參數 描述
to 必需。規定 email 接收者。
subject 必需。規定 email 的主題。注釋:該參數不能包含任何新行字元。
message 必需。定義要發送的訊息。應使用 LF (\n) 來分隔各行。每行應該限制在 70 個字元內。
headers 可選。規定附加的標題,比如 From、Cc 和 Bcc。應當使用 CRLF (\r\n) 分隔附加的標題。
parameters 可選。對郵件發送程式規定額外的參數。

 

執行個體:

<html><head><meta charset="utf-8"><title>學習教程</title></head><body><?phpfunction spamcheck($field){    // filter_var() 過濾 e-mail    // 使用 FILTER_SANITIZE_EMAIL 過濾器從字串中刪除電子郵件的非法字元    $field=filter_var($field, FILTER_SANITIZE_EMAIL);    //filter_var() 過濾 e-mail    // 使用 FILTER_VALIDATE_EMAIL 過濾器驗證電子郵件地址的值    if(filter_var($field, FILTER_VALIDATE_EMAIL))    {        return TRUE;    }    else    {        return FALSE;    }}if (isset($_REQUEST[‘email‘])){    // 如果接收到郵箱參數則發送郵件    // 判斷郵箱是否合法    $mailcheck = spamcheck($_REQUEST[‘email‘]);    if ($mailcheck==FALSE)    {        echo "非法輸入";    }    else    {            // 發送郵件        $email = $_REQUEST[‘email‘] ;        $subject = $_REQUEST[‘subject‘] ;        $message = $_REQUEST[‘message‘] ;        mail("[email protected]", "Subject: $subject",$message, "From: $email" );        echo "Thank you for using our mail form";    }}else{     // 如果沒有郵箱參數則顯示表單    echo "<form method=‘post‘ action=‘mailform.php‘>    Email: <input name=‘email‘ type=‘text‘><br>    Subject: <input name=‘subject‘ type=‘text‘><br>    Message:<br>    <textarea name=‘message‘ rows=‘15‘ cols=‘40‘>    </textarea><br>    <input type=‘submit‘>    </form>";}?></body></html>

 

PHP 寄送電子郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.