Creates an instance of a class and joins the attachment
$mail = new Html_mime_mail ();
$mail->add_attachment ($attachment, $myfile _name, ' Application/octet-stream ');
/*---------------------This section demonstrates how to send an HTML letter---------------------------------------
$filename = ' background.gif ';
$backgrnd = fread ($fp = fopen ($filename, ' R '), FileSize ($filename));
Fclose ($FP);
$text = ' This is a test. ';
$html = '
$mail->add_html_image ($backgrnd, ' background.gif ', ' image/gif ');
$mail->add_html ($html, $text);
-------------------------------------------------------------------------------------*/
Read the body, encapsulate and send the letters
$mail->body= $bodytext;
$mail->build_message ();
Send a hint message
echo "<script Language=javascript>alert (' Letter ok, press OK to return!") '); window.location= ' default.htm ' </script> ';
}
else{//If no attachments
$backvalue =mail ($receivemailbox, $subject, $bodytext, "from:". $sendmailbox. "\nreply-to:". $sendmailbox. "\nx-mailer:php/". Phpversion ());
if ($result) {
echo "<script Language=javascript>alert (' Letter ok, press OK to return!") '); window.location= ' default.htm ' </script> ';
}
else{
echo "<script language=javascript>backvalue=window.confirm (' Letter failed! Maybe the server is too busy! Do you want to send it again? '); if (Backvalue) {location.reload ()}else{window.location= ' default.htm '}</script> ';
}
}
?>
Html_mime_mail.inc This class is available in the elite area. I'll borrow it for a while.
?
Class html_mime_mail{
var $headers;
var $body;
var $multipart;
var $mime;
var $html;
var $html _text;
var $html _images = Array ();
var $cids = array ();
var $do _html;
var $parts = array ();
/***************************************
* * Constructor function. Sets the Headers
* * if supplied.
***************************************/
function Html_mime_mail ($headers = ' ") {
$this->headers = $headers;
}
/***************************************
* * Adds a HTML part to the mail.
* * Also replaces image names with
* * content-id ' s.
***************************************/
function add_html ($html, $text) {
$this->do_html = 1;
$this->html = $html;
$this->html_text = $text;
if (Is_array ($this->html_images) and Count ($this->html_images) > 0) {
For ($i =0 $i <count ($this->html_images); $i + +) {
$this->html = ereg_replace ($this->html_images[$i] [' name '], ' cid: '. $this->html_images[$i] [' CID '], $this- >html);
}
}
}
/***************************************
* * Builds HTML part of email.
***************************************/
function build_html ($orig _boundary) {
$sec _boundary = ' =_ '. MD5 (Uniqid (Time ()));
$thr _boundary = ' =_ '. MD5 (Uniqid (Time ()));
if (!is_array ($this->html_images)) {
$this->multipart.= '--'. $orig _boundary. " \ r \ n ";
$this->multipart.= ' content-type:multipart/alternative; Boundary= "'. $sec _boundary." \ "\r\n\r\n\r\n";
$this->multipart.= '--'. $sec _boundary. " \ r \ n ";
$this->multipart.= ' Content-type:text/plain '. \ r \ n ";
$this->multipart.= ' Content-transfer-encoding:7bit '. \r\n\r\n ";
$this->multipart.= $this->html_text. " \r\n\r\n ";
$this->multipart.= '--'. $sec _boundary. " \ r \ n ";
$this->multipart.= ' content-type:text/html '. \ r \ n ";
$this->multipart.= ' Content-transfer-encoding:7bit '. \r\n\r\n ";
$this->multipart.= $this->html. " \r\n\r\n ";
$this->multipart.= '--'. $sec _boundary. " --\r\n\r\n ";
}else{
$this->multipart.= '--'. $orig _boundary. " \ r \ n ";
$this->multipart.= ' content-type:multipart/related; Boundary= "'. $sec _boundary." \ "\r\n\r\n\r\n";
$this->multipart.= '--'. $sec _boundary. " \ r \ n ";
$this->multipart.= ' content-type:multipart/alternative; Boundary= "'. $thr _boundary." \ "\r\n\r\n\r\n";
$this->multipart.= '--'. $thr _boundary. " \ r \ n ";
$this->multipart.= ' Content-type:text/plain '. \ r \ n ";
$this->multipart.= ' Content-transfer-encoding:7bit '. \r\n\r\n ";
$this->multipart.= $this->html_text. " \r\n\r\n ";
$this->multipart.= '--'. $thr _boundary. " \ r \ n ";
$this->multipart.= ' content-type:text/html '. \ r \ n ";
$this->multipart.= ' Content-transfer-encoding:7bit '. \r\n\r\n ";
$this->multipart.= $this->html. " \r\n\r\n ";
$this->multipart.= '--'. $thr _boundary. " --\r\n\r\n ";
For ($i =0 $i <count ($this->html_images); $i + +) {
$this->multipart.= '--'. $sec _boundary. " \ r \ n ";
$this->build_html_image ($i);
}
$this->multipart.= "--" $sec _boundary. " --\r\n\r\n ";
}
}
/***************************************
* * Adds an image to the list of embedded
* * images.
***************************************/
function Add_html_image ($file, $name = ', $c _type= ' Application/octet-stream ') {
$this->html_images[] = array (' body ' => $file,
' Name ' => $name,
' C_type ' => $c _type,
' CID ' => MD5 (uniqid (Time ()));
}
/***************************************
* * Adds a file to the list of attachments.
***************************************/
function Add_attachment ($file, $name = ', $c _type= ' Application/octet-stream ') {
$this->parts[] = array (' body ' => $file,
' Name ' => $name,
' C_type ' => $c _type);
}
/***************************************
* * Builds an embedded image part of
* * HTML mail.
***************************************/
function Build_html_image ($i) {
$this->multipart.= ' Content-type: '. $this->html_images[$i] [' C_type '];
if ($this->html_images[$i] [' name ']!= ') $this->multipart. = '; Name= "'. $this->html_images[$i [' name ']." \ "\ r \ n";
else $this->multipart. = "\ r \ n";
/***************************************
* * Use the use of this method to deliver using direct
* * SMTP connection. Relies upon Manuel Lemos '
* * SMTP mail delivery class available at:
* * http://phpclasses.upperdesign.com
**
* * void Smtp_send (string *name* of SMTP object,
* * String from address,
* * Array to addresses,
* * Array Headers,
* * String The body)
***************************************/
function Smtp_send ($smtp _obj, $from _addr, $to _addr) {
Global $ $smtp _obj;
$SMTP _obj = $ $smtp _obj;
if (substr ($this->headers,-2) = = "\ r \ n") $this->headers = substr ($this->headers,0,-2);
$this->headers = Explode ("\ r \ n", $this->headers);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.