![]() |
溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - 105-1-物件導向程式設計-資管二乙 - 第15週-電子郵件 |
| 第15週-電子郵件電子郵件 <?php // 本程式的送信機制: // 在ccs.cust.edu.tw上有授權,就是有帳號與密碼,並且設定的路徑 // 為網站伺服器可存取的位置(http://ccs.cust.edu.tw/~s10314Dxxx/www/)。 // 將此程式上傳至 http://ccs.cust.edu.tw/~s1031Dxxx/www/infosend1.php // 請以瀏覽器執行 http://ccs.cust.edu.tw/~s10314Dxxx/infosend1.php function display_send_page(){ echo "<html><head><title> Email 測試(可以利用前端夾檔方式寄送)</title> <link rel='stylesheet' type='text/css' href='style.css'> </head>"; $cname=trim($_POST["cname"]); $mailto=trim($_POST["mailto"]); $subject=trim($_POST["subject"]); $message=trim($_POST["message"]); $to_name = "=?utf-8?B?" . base64_encode("$cname") . "?="; $to_email = $mailto; $from_name = "=?utf-8?B?" . base64_encode("中華科技大學") . "?="; $from_email = "ven@cc.cust.edu.tw"; $subject = "=?utf-8?B?" . base64_encode("$subject") . "?="; $mime_boundary = md5(uniqid(mt_rand(), TRUE)); $header = "From: $from_name<$from_email>\r\n"; $header .= "To: $to_name<$to_email>\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=". $mime_boundary . "\r\n"; $content = "This is a multi-part message in MIME format.\r\n"; $content .= "--$mime_boundary\r\n"; $content .= "Content-Type: text/plain; charset=utf-8\r\n"; $content .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; $content .="$cname 您好\r\n\r\n"; $content .= "$message\r\n"; $content .= "--$mime_boundary\r\n"; if ($_FILES{"myfile"}{"name"} != "") { $file = $_FILES{"myfile"}{"tmp_name"}; $file_name = $_FILES{"myfile"}{"name"}; $content_type = $_FILES{"myfile"}{"type"}; $fp = fopen($file, "rb"); $data = fread($fp, filesize($file)); $data = chunk_split(base64_encode($data)); $content .= "Content-Type: $content_type; name=$file_name\r\n"; $content .= "Content-Disposition: attachment; filename=$file_name\r\n"; $content .= "Content-Transfer-Encoding: base64\r\n\r\n"; $content .= "$data\r\n"; $content .= "--$mime_boundary--\r\n"; } if (mail($to_email, $subject, $content, $header)) echo "$cname ---- $email ---- 寄信成功!"; else echo "$cname ---- $email ---- 寄信失敗!"; } ?> 作業 撰寫一電子郵件寄信程式 第一個頁面有收信人郵件地址(mailto text), 中文姓名 (cname text), 郵件主旨(subject text), 郵件內容(message textarea) , 與附加檔案(myfile file) 並有一個寄送按鈕, 寄出後顯示成功/失敗 可參考 http://cc.cust.edu.tw/~ven/infosend1.php
|
|
中華科技大學數位化學習歷程 - 意見反應 | ![]() |