Describes in detail the Jmai component of PHP and the sending mail instance. % OnerrorresumenextDimJMail, contentIdSetJMailServer. CreateObject (JMail. Message) JMail. Charsetgb2312 Mail character set, US-ASCIIJMail.ISOEncodeHeaders by default
<%
On error resume next
Dim JMail, contentId
Set JMail = Server. CreateObject ("JMail. Message ")
JMail. Charset = "gb2312" Mail character set, "US-ASCII" by default"
JMail. ISOEncodeHeaders = False: whether to perform ISO encoding. the default value is True.
Sender information (assign values using variables)
JMail. From = "webjxcom@163.com" sender address
JMail. FromName = "website administrator" name of the sender
JMail. Subject = "Subject"
Authentication
User name for JMail. MailServerUserName = "webjx" authentication
JMail. MailServerPassword = "webjx" authentication password
Set priority from 1 to 5. the higher the priority, the higher the 3 is normal.
JMail. Priority = 1
JMail. AddHeader "Originating-IP", Request. ServerVariables ("REMOTE_ADDR ")
Add one recipient (variable email: recipient address). Multiple recipients can be added in the same statement.
JMail. AddRecipient ("5ss@163.com ")
Add the attachment [variable filename: the absolute address of the attachment file to ensure that the user IUSR _ machine name has access permissions]
[Set the parameter to "True" or "False" in the "Inline" mode]
ContentId = JMail. AddAttachment (Server. MapPath ("jmail. asp"), True)
Email Subject (HTML (note the Attachment link in the letter ))
JMail. AppendBodyFromFile (Server. MapPath ("/Love/Inc/Mailend.txt "))
JMail. HTMLBody =" Email body
Email body
Email body"
Email Subject (text)
JMail. Body = "our emails are in HTML format, but your email viewing software may not support it... Body, body, body"
Send [Call Format: objJMail. Send ([username: password @] SMTPServerAddress [: Port])]
JMail. Send ("smtp.163.com ")
Close and clear objects
JMail. Close ()
Set JMail = Nothing
If err. number <> 0 then
Response. write "sending failed! "
Else
Response. write "email sent successfully! "
End if
%>
Class smtp
{
/* Public Variables */
Var $ smtp_port;
Var $ time_out;
Var $ host_name;
Var $ log_file;
Var $ relay_host;
Var $ debug;
Var $ auth;
Var $ user;
Var $ pass;
/* Private Variables */
Var $ sock;
/* Constractor */
Function smtp ($ relay_host = "", $ smtp_port = 25, $ auth = false, $ user, $ pass)
{
$ This-> debug = FALSE;
$ This-> smtp_port = $ smtp_port;
$ This-> relay_host = $ relay_host;
$ This-> time_out = 30; // is used in fsockopen ()
#
$ This-> auth = $ auth; // auth
$ This-> user = $ user;
$ This-> pass = $ pass;
#
$ This-> host_name = "localhost"; // is used in HELO command
$ This-> log_file = "";
$ This-> sock = FALSE;
}
/* Main Function */
Function sendmail ($ to, $ from, $ subject = "", $ body = "", $ mailtype, $ cc = "", $ bcc = "", $ additional_headers = "")
{
$ Mail_from = $ this-> get_address ($ this-> strip_comment ($ from ));
$ Body = ereg_replace ("(^ | () (.)", "1.3", $ body );
$ Header = "maid: 1.0 ";
If ($ mailtype = "HTML "){
$ Header. = "Content-Type: text/html ";
}
$ Header. = "To:". $ ."";
If ($ cc! = ""){
$ Header. = "Cc:". $ cc ."";
}
$ Header. = "From: $ from <". $ from. "> ";
$ Header. = "Subject:". $ subject ."";
$ Header. = $ additional_headers;
$ Header. = "Date:". date ("r ")."";
$ Header. = "X-Mailer: By Redhat (PHP/". phpversion ().")";
List ($ msec, $ sec) = explode ("", microtime ());
$ Header. = "Message-ID: <". date ("YmdHis", $ sec ). ". ". ($ msec * 1000000 ). ". ". $ mail_from. "> ";
$ TO = explode (",", $ this-> strip_comment ($ ));
If ($ cc! = ""){
$ TO = array_merge ($ TO, explode (",", $ this-> strip_comment ($ cc )));
}
If ($ bcc! = ""){
$ TO = array_merge ($ TO, explode (",", $ this-> strip_comment ($ bcc )));
}
$ Sent = TRUE;
Foreach ($ TO as $ rcpt_to ){
$ Rcpt_to = $ this-> get_address ($ rcpt_to );
If (! $ This-> smtp_sockopen ($ rcpt_to )){
$ This-> log_write ("Error: Cannot send email to". $ rcpt_to ."");
$ Sent = FALSE;
Continue;
}
If ($ this-> smtp_send ($ this-> host_name, $ mail_from, $ rcpt_to, $ header, $ body )){
$ This-> log_write ("E-mail has been sent to <". $ rcpt_to. "> ");
} Else {
$ This-> log_write ("Error: Cannot send email to <". $ rcpt_to. "> ");
$ Sent = FALSE;
}
Fclose ($ this-> sock );
$ This-> log_write ("Disconnected from remote host ");
& N
Http://www.bkjia.com/PHPjc/509200.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/509200.htmlTechArticle% On error resume next Dim JMail, contentId Set JMail = Server. createObject ("JMail. message ") JMail. charset = "gb2312" character set, default: "US-ASCII" JMail. ISOEncodeHeaders =...