php簡單實現發送帶附件的郵件,php發送附件郵件_PHP教程

來源:互聯網
上載者:User

php簡單實現發送帶附件的郵件,php發送附件郵件


本文執行個體講述了php簡單實現發送帶附件的郵件。分享給大家供大家參考。具體如下:

下面是靜態html代碼:

  帶附件的郵件發送       

sendmail.php檔案代碼:

<?php  //獲得表單資訊 $from = $_POST['from']; $to = $_POST['to'];  $subject = $_POST['subject'];  $body = $_POST['body'];  // 定義分界線  $boundary = "345894369383"; //分界線是一串無規律的字元 //設定header $header = "Content-type: multipart/mixed; boundary= $boundary/r/n";  $header .= "From:$from/r/n";  //獲得上傳檔案的檔案內容 $file = $_FILES['upload_file']['tmp_name'];  //確定上傳檔案的MIME類型  $mimeType = $_FILES['upload_file']['type'];  //獲得上傳檔案的檔案名稱  $fileName = $_FILES['upload_file']['name'];  //讀取上傳檔案  $fp = fopen($file, "r"); //開啟檔案 $read = fread($fp, filesize($file)); //讀入檔案 $read = base64_encode($read); //base64編碼  $read = chunk_split($read); //切割字串 //建立郵件的主體,分為郵件內容和附件內容兩部分 $body = "--$boundary  Content-type: text/plain; charset=iso-8859-1  Content-transfer-encoding: 8bit  $body  --$boundary  Content-type: $mimeType; name=$fileName  Content-disposition: attachment; filename=$fileName  Content-transfer-encoding: base64  $read  --$boundary--";  //發送郵件 並輸出是否發送成功的資訊 if(mail($to, $subject,$body,$header))  {   echo "信件發送成功";  } else  {   echo "信件發送失敗";  } ?>

希望本文所述對大家的php程式設計有所協助。

http://www.bkjia.com/PHPjc/1014426.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1014426.htmlTechArticlephp簡單實現發送帶附件的郵件,php發送附件郵件 本文執行個體講述了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.