>백엔드 개발 >PHP 튜토리얼 >发现一个发送mime邮件的类。_PHP教程

发现一个发送mime邮件的类。_PHP教程

WBOY
WBOY원래의
2016-07-13 17:27:31783검색

parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } /* * void add_attachment(string message, * [string name], * [string ctype]) * 將附加物(附檔)加入郵件物件 */ function add_attachment($message, $name = "", $ctype = "application/octet-stream") { $this->parts[] = array( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name); } /* * void build_message(array part) * 建立 multipart 郵件的訊息部份 */ function build_message($part) { $message = $part["message"]; $message = chunk_split(base64_encode($message)); $encoding = "base64"; return "Content-Type: " . $part["ctype"] . ($part["name"] ? "; name="".$part["name"].""" : "") . " Content-Transfer-Encoding: $encoding $message "; } /* * void build_multipart() * 建立一封 multipart 郵件 */ function build_multipart() { $boundary = "b" . md5(uniqid(time())); $multipart = "Content-Type: multipart/mixed; " . "boundary = $boundary " . "This is a MIME encoded message. --$boundary"; for ($i = sizeof($this->parts) - 1; $i >= 0; $i--) { $multipart .= " " . $this->build_message($this->parts[$i]) . "--$boundary"; } return $multipart . "-- "; } /* * string get_mail() * 傳回已組合完成的郵件 */ function get_mail($complete = true) { $mime = ""; if (!empty($this->from)) $mime .= "From: " . $this->from . " "; if (!empty($this->headers)) $mime .= $this->headers . " "; if ($complete) { if (!empty($this->to)) $mime .= "To: $this->to "; if (!empty($this->subject)) $mime .= "Subject: $this->subject "; } if (!empty($this->body)) $this->add_attachment($this->body, "", "text/plain"); $mime .= "MIME-Version: 1.0 " . $this->build_multipart(); return $mime; } /* * void send() * 寄出這封信(最後一個被呼叫的函式) */ function send() { $mime = $this->get_mail(false); mail($this->to, $this->subject, "", $mime); } } // 類別結束 ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/531858.htmlTechArticleparts = array(); $this->to = ; $this->from = ; $this->subject = ; $this->body = ; $this->headers = ; } /* * void add_attachment(string message, * [string name], * [string ctype]) *...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.