SMTP.?
/***********************************
PHP MIME SMTP ver 1.0 powered by Boss_ch, Unigenius Soft ware Co. Ltd
All rights reserved, Copyright 2000;
This class sends MIME-type messages using PHP through the SMTP sock operation, and can send
HTML format body, accessories, using base64 code
This version is for the individual to send, and the number of mass version is different, each sent to a person, on the code again, in the receiver's view, just send him a person.
For many people, send only once, through multiple RCPT to command sent to a different people's mailbox,
Description
Please set $hostname to the default SMTP server you have permission for or to specify when new
Change the $charset to your default character set
If there is a picture in the Html body, please use the absolute path reference "Image.gif";
and connected to the Internet to ensure that the program can read the image of the data information
If the Html body is submitted through the form, first use Stripslashes ($html _body) to preprocess the body content.
Style sheet files used in Html, do not use references such as <link > to directly place the stylesheet definition in the
<style></style> tags in
Reprint please retain this copyright information, Bugs report:boss_ch@china.com
*************************************/
if (!isset ($__smtp_class__)) {
$__smtp_class__=1;
Class SMTP
{
var $hostname = "";
var $port = 25;
var $connection = 0;
var $debug = 1;
var $timeout = 30;
var $err _str;
var $err _no;
var $autocode =true;
var $charset = "GB2312";
var $subject = "";
var $body = "";
var $attach = "";
var $temp _text_body;
var $temp _html_body;
var $temp _body_images;
var $bound _begin= "=====powered_by_boss_chen_";
var $bound _end= "_046484063883_=====";
//For whether text body, HTML body has no, must have different MIME headers
if (! $hava _att) $this->body.= "This is a multi-part message in MIME format.\r\n\r\n";
Body identification, if the attachment is already encoded, then in the body does not need this sentence
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->parse_html_body ($html _body);
if ($text _body)
{
$this->body.= "content-type:multipart/alternative;
Boundary=\ "";
$bound _level++;
$this->body.= $this->bound_begin. $bound _level. $this->bound_end. " \ "\r\n\r\n";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->body.= "content-type:text/plain;\r\n";
$this->body.= "charset=\" $this->charset\ "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($text _body)). " \ r \ n ";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->body.= "content-type:text/html;\r\n";
$this->body.= "charset=\" $this->charset\ "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($this->temp_html_body)). " \ r \ n ";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " --\r\n\r\n ";
$bound _level--;
}
Else
{
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->body.= "content-type:text/html;\r\n";
$this->body.= "charset=\" $this->charset\ "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($this->temp_html_body)). " \ r \ n ";
//Body code, with or without text, in a different format.
for ($i =0; $i <count ($this->temp_body_images); $i + +)
{
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->body.= "Content-type:" $this->temp_body_images[$i][type]. "
Name=\ "";
$this->body.= $this->temp_body_images[$i][name]. " \ "\ r \ n";
$this->body.= "content-transfer-encoding:base64\r\n";
$this->body.= "Content-id: <". $this->temp_body_images[$i][cid]. " >\r\n ";
$this->body.= "\ r \ n". Chunk_split (Base64_encode (stripslashes ($this->temp_body_images[$i][data))). " \ r \ n ";
}
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " --\r\n\r\n ";
$bound _level--;
}
else//There is or no picture, above is the processing of the picture, the following is no picture of the processing
{
$this->temp_html_body= $html _body;
if ($text _body)
{
$bound _level++;
$this->body.= "content-type:multipart/alternative;
Boundary=\ "";
$this->body.= $this->bound_begin. $bound _level. $this->bound_end. " \ "\r\n\r\n";
if (! $hava _att) $this->body.= "\r\nthis is a multi-part message in MIME format.\r\n\r\n";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->body.= "content-type:text/plain;\r\n";
$this->body.= "charset=\" $this->charset\ "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($text _body)). " \ r \ n ";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->body.= "content-type:text/html;\r\n";
$this->body.= "charset=\" $this->charset\ "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($this->temp_html_body)). " \ r \ n ";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " --\r\n\r\n ";
$bound _level--;
}
Else
{
$this->body.= "content-type:text/html;\r\n";
$this->body.= "charset=\" $this->charset\ "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($this->temp_html_body)). " \ r \ n ";
//Body code, with or without text, in a different format.
}//End Else
}
else//If there is no HTML body, only the text body
{
$this->body.= "Content-type:text/plain;
Charset=\ "$this->charset\" "\ r \ n";
$this->body.= "content-transfer-encoding:base64 \ r \ n";
$this->body.= "\ r \ n" Chunk_split (Base64_encode stripslashes ($text _body)). " \ r \ n ";
}
}//End Function default
Function buildbody ($text _body=null, $html _body=null, $att =null)
{
$this->body= "mime-version:1.0\r\n";
if (null== $att or (@count ($att) ==0)//If no attachment is available, view the type of the body;
{
$encode _level=0;
$this->build_content ($encode _level, $text _body, $html _body);
//If there are no attachments,
// ********************************************************
else//If there is an attachment,
{
$bound _level=0;
$this->body.= "content-type:multipart/mixed;
Boundary=\ "";
$bound _level++;
$this->body.= $this->bound_begin. $bound _level. $this->bound_end. " \ "\r\n\r\n";
$this->body.= "This are a multi-part message in MIME format.\r\n\r\n";
$this->body.= "--" $this->bound_begin. $bound _level $this->bound_end. " \ r \ n ";
$this->build_content ($bound _level, $text _body, $html _body,true); Into the body part
if (Empty ($from _mail) or empty ($to _mail))
{
$this->err_str= "did not specify the correct mail address:". $from _mail. " Receiver: ". $to _mail;
return false;
}
if (GetType ($to _mail)!= "Array")
$to _mail=split (",", $to _mail); If it is not an array, convert the arrays, even if there is only one sending object;
if (GetType ($to _name)!= "Array")
$to _name=split (",", $to _name); If it is not an array, convert the arrays, even if there is only one sending object;
$this->buildbody ($text _body, $html _body, $att);
The contents of all letters are the same, can only be edited once, and for different addressee, need different head
if (! $this->open ()) return false;
if (! $this->command ("HELO $this->hostname", 3, ")" return false;
Establish a link with the server
if (! $this->open ()) return false;
if (! $this->command ("HELO $this->hostname", 3, ")" return false;
for ($i =0; $i <count ($to _mail); $i + +)
{
$this->buildhead ($from _name, $to _name[$i], $from _mail, $to _mail[$i], $subject);
if (! $this->command ("RSET", 3, ")" return false;
if (! $this->command ("MAIL from:". $from _mail,3, "a") return false;
if (! $this->command ("RCPT to:". $to _mail[$i],3, "a") return false;
if (! $this->command ("DATA", 3, "354") return false;
Preparing to send mail
if ($this->debug) $this->outdebug ("sending subject;");
if (!fputs ($this->connection, $this->subject)) {$this->err_str= "error sending headers!" "; return false;}
if ($this->debug) $this->outdebug ("Sending body;");
if (!fputs ($this->connection, $this->body)) {$this->err_str= "error sending body!" "; return false;}
if (!fputs ($this->connection, ". \ r \ \ \ \ \ \ \ \ \ \ \ \ \ \ \")) {$this->err_str= "error sending body "; return false;} Text sent out, exit;
$resp =fgets ($this->connection,256);
if ($this->debug)
$this->outdebug ("$resp");
if (substr ($RESP, 0, 1)!= "2")
{
$this->err_str= "After sending, the server does not respond!! ";
return false;
}
Send mail
}
if (! $this->command ("QUIT", 3, "221") return false;
$this->close ();
return true;
}
}//end class Define
}//end if (!isset ($__smtp_class__))
?>
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.