php簡單實現傳送帶附件的郵件

2022-10-06 10:33:14 字數 1369 閱讀 2607

下面是靜態html**:

帶附件的郵件傳送

sendmail.php檔案**:

<?php //獲得表單資訊

$from = $_post['from'];

$to = $_post['to'];

$subject = $_post['subje程式設計客棧ct'];

$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

contenwww.cppcns.comt-transfer-encoding: base64

$read

--$boundary--";

//傳送郵件 並輸出是否傳送成功的資訊

if(mail($to, $subject,$body,$header))

else

?>

本文位址:

php實現的傳送帶附件郵件類例項

emailclass.php類檔案如下 class cmailfile function attach file filename,downfilename,mimetype,mime filename function encode file sourcefile return encoded f...

傳送帶附件的郵件

import smtplib from email.mime.text import mimetext from email.mime.multipart import mimemultipart from email.utils import formataddr from config impo...

傳送帶附件的郵件

我們平時需要使用 python 傳送各類郵件,這個需求怎麼來實現?答案其實很簡單,smtplib 和 email庫可以幫忙實現這個需求。smtplib 和 email 的組合可以用來傳送各類郵件 普通文字,html 形式,帶附件,郵件,帶的郵件等等。我們這裡將會分幾節把傳送郵件功能解釋完成。smtp...