Smtp mail sending example

Source: Internet
Author: User
Test_smtp.php (as the mainstream development language) & lt ;? Require (smtp. php (as the mainstream development language); & #36; smtpnewsmtp_class; & #36; smtp-& gt; host_namemail.xiaocui.com; & #36; smtp-& gt; localhostlocalhost; & # test_smtp.php (as the mainstream development language)

Require ("smtp. php (as the mainstream development language )");

$ Smtp = new smtp_class;

$ Smtp-> host_name = "mail.xiaocui.com ";
$ Smtp-> localhost = "localhost ";
$ From = "webmaster@xiaocui.com ";
$ To = "root@xiaocui.com ";
If ($ smtp-> SendMessage (
$ From,
Array (
$
),
Array (
"From: $ from ",
"To: $ ",
"Subject: Testing Manuel Lemos SMTP class"
),
"Hello $ to, It is just to let you know that your SMTP class is working just fine. Bye ."))
Echo "Message sent to $ to OK .";
Else
Echo "Cound not send the message to $ to. Error:". $ smtp-> error .""
?>

Smtp. php (as the mainstream development language)


Class smtp_class
{
Var $ host_name = "";
Var $ host_port = 25;
Var $ localhost = "";
Var $ timeout = 0;
Var $ error = "";
Var $ debug = 1;
Var $ esmtp = 1;
Var $ esmtp_host = "";
Var $ esmtp_extensions = array ();
Var $ maximum_piped_recipients = 100;

/* Private variables-do not access (a favorite of small websites )*/

Var $ state = "Disconnected ";
Var $ connection = 0;
Var $ pending_recipients = 0;

/* Private methods-do not call */

Function OutputDebug ($ message)
{
Echo $ message ,"
";
}

Function GetLine ()
{
For ($ line = "";;)
{
If (feof ($ this-> connection ))
{
$ This-> error = "reached the end of stream while reading from socket ";
Return (0 );
}
If ($ data = fgets ($ this-> connection, 100) = false)
{
$ This-> error = "it was not possible to read line from socket ";
Return (0 );
}
$ Line. = $ data;
$ Length = strlen ($ line );
If ($ length> = 2
& Substr ($ line, $ length-2, 2) = "")
{
$ Line = substr ($ line, 0, $ length-2 );
If ($ this-> debug)
$ This-> OutputDebug ("<$ line ");
Return ($ line );
}
}
}

Function PutLine ($ line)
{
If ($ this-> debug)
$ This-> OutputDebug ("> $ line ");
If (! Fputs ($ this-> connection, "$ line "))
{
$ This-> error = "it was not possible to write line to socket ";
Return (0 );
}
Return (1 );
}

Function PutData ($ data)
{
If (strlen ($ data ))
{
If ($ this-> debug)
$ This-> OutputDebug ("> $ data ");
If (! Fputs ($ this-> connection, $ data ))
{
$ This-> error = "it was not possible to write data to socket ";
Return (0 );
}
}
Return (1 );
}

Function VerifyResultLines ($ code, $ responses = "")
{
If (GetType ($ responses )! = "Array ")
$ Responses = array ();
Unset ($ match_code );

While ($ line = $ this-> GetLine ($ this-> connection )))
{

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.