PHP Mail 簡介

來源:互聯網
上載者:User

標籤:style   color   使用   os   io   檔案   for   cti   

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

mail(to,subject,message,headers,parameters);

參數 描述
to 必需。規定 email 接收者。
subject 必需。規定 email 的主題。注釋:該參數不能包含任何新行字元。
message 必需。定義要發送的訊息。應使用 LF (\n) 來分隔各行。
headers

可選。規定附加的標題,比如 From、Cc 以及 Bcc。

應當使用 CRLF (\r\n) 分隔附加的標題。

parameters 可選。對郵件發送程式規定額外的參數。

 

 

 

 

 

 

注釋:PHP 需要一個已安裝且正在啟動並執行郵件系統,以便使郵件函數可用。所用的程式通過在 php.ini 檔案中的配置設定進行定義。

PHP 簡易 E-Mail

通過 PHP 寄送電子郵件的最簡單的方式是發送一封文本 email。

在下面的例子中,我們首先聲明變數($to, $subject, $message, $from, $headers),然後我們在 mail() 函數中使用這些變數來發送了一封 e-mail:

<?php$to = "[email protected]";$subject = "Test mail";$message = "Hello! This is a simple email message.";$from = "[email protected]";$headers = "From: $from";mail($to,$subject,$message,$headers);echo "Mail Sent.";?>
PHP Mail Form

通過 PHP,您能夠在自己的網站製作一個反饋表單。下面的例子向指定的 e-mail 地址發送了一條簡訊:

<html><body><?phpif (isset($_REQUEST[‘email‘]))//if "email" is filled out, send email  {  //send email  $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//if "email" is not filled out, display the form  {  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>




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.