The class that stabilizes the test SMTP send mail (please pay the use method), thank you very much

Source: Internet
Author: User
For a stable and tested SMTP Send mail class (please pay the use method), thank you very much!
I looked for a few, some can not be used, can't send out, some incredibly no text;
There is a body of these have, but did not send a few words said "account has been locked", discuz\phpwind these e-mail classes are too complex to peel out!

Checheras!!!
With the Mail function and IIS SMTP, it is always said address invalid! how to change addresses are not: "AAA" or "aaa@163.com", are wrong

If the larger, lein_urg@163.com, please send to the mailbox, thank you!
E-mail 20 points from Kazakhstan, if the right word 60 points up!

------Solution--------------------
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 = +, $auth = False, $user, $pass)
{
debug = FALSE, $this
$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 = get_address, $this, $this, Strip_comment ($from));
$body = Ereg_replace ("(^| ( \ n)) (\.) "," \1.\3 ", $body);
$header. = "mime-version:1.0\r\n";
if ($mailtype = = "HTML")
{
$header. = "content-type:text/html\r\n";
}
$header. = "To:". $to. " \ r \ n ";
if ($cc! = "")
{
$header. = "Cc:". $cc. "\ r \ n";
}
$header. = "From: $from <". $from. " > \ r \ n ";
$header. = "Subject:". $subject. " \ r \ n ";
$header. = $additional _headers;
$header. = "Date:". Date ("R"). " \ r \ n ";
$header. = "X-mailer:by Redhat (php/". Phpversion (). ") \ r \ n ";
List ($msec, $sec) = Explode ("", Microtime ());
$header. = "Message-id: <". Date ("Ymdhis", $sec). ".". ($msec *1000000). ". ". $mail _from. "> \ r \ n";
$TO = Explode (",", $this-strip_comment ($to));

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. " \ n ");
$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. " > \ n ");
}
Else
{
$this-Log_write ("Error:cannot Send email to <". $rcpt _to. " > \ n ");
$sent = FALSE;
}
Fclose ($this-sock);
$this-Log_write ("Disconnected from remote host\n");
}
return $sent;
  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.