PHP win next socket way e-mail class _php tutorial

Source: Internet
Author: User
Tags email account
Copy CodeThe code is as follows:
/*
* php smtp Send mail Scoket class
* zhozphpsmtpsendmail.php
* Created on 2008/09/02 zhoz.com
* @author Zhoz
* v 1.72 update 2008/09/26 zhoz. Com
*/
Class Zhozphpsmtpsendmail {
Your SMTP server vendor, which can be a domain name or IP address
var $smtp = "";
SMTP requires an authentication value of 1, no authentication value of 0, and now most of the SMTP service providers have to verify, if not clear, contact your SMTP service provider.
var $check = 1;
Name of your email account
var $username = "";
Your e-mail password
var $password = "";
This email must be email on the sending server.
var $s _from = "";
/*
* Function: Initialization setting of sending letter
* $from your letters Geumcheon 魃?
* $password your e-mail password
* $SMTP your SMTP server vendor, which can be a domain name or IP address
* $check SMTP requires authentication set to 1 does not require an authentication value of 0, now most of the SMTP service providers have to verify
*/
function Zhozphpsmtpsendmail ($from, $password, $smtp, $check = 1) {
if (Preg_match ("/^[^\d\-_][\w\-]*[^\-_]@[^\-][a-za-z\d\-]+[^\-") (\.[ ^\-][a-za-z\d\-]*[^\-]) *\. [A-za-z] {2,3}/", $from)) {
$this->username = substr ($from, 0, Strpos ($from, "@"));
$this->password = $password;
$this->smtp = $smtp? $SMTP: $this->smtp;
$this->check = $check;
$this->s_from = $from;
}
}
/*
* Function: Send mail
* $to Target Mailbox
* $from Source Mailbox
* $subject Mail Header
* $message Mail Content
*/
function Zhoz_send ($to, $from, $subject, $message) {
Connecting to a server
$fp = Fsockopen ($this->smtp, $errno, $ERRSTR, 60);
if (! $fp) return "failed to join Server". __line__;
Set_socket_blocking ($fp, true);
$lastmessage =fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! =) Return "error message 1: $lastmessage". __line__;
HELO
$yourname = "Yourname";
if ($this->check = = "1") $lastact = "EHLO". $yourname. " \ r \ n ";
else $lastact = "HELO". $yourname. " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = = fgets ($fp, 512);
if (substr ($lastmessage, 0,3)! =) return "error message 2: $lastmessage". __line__;
while (true) {
$lastmessage = fgets ($FP, 512);
if ((substr ($lastmessage, 3,1)! = "-") or (Emptyempty ($lastmessage)))
Break
}
Identity verification
if ($this->check== "1") {
Validation begins
$lastact = "AUTH LOGIN". " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = 334) return "error message 3: $lastmessage". __line__;
User name
$lastact =base64_encode ($this->username). " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = 334) return "error message 4: $lastmessage". __line__;
User password
$lastact =base64_encode ($this->password). " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = "235") return "error message 5: $lastmessage". __line__;
}
From:
$lastact = "MAIL from: <". $this->s_from. ">\r\n";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! =) Return "error message 6: $lastmessage". __line__;
To:
$lastact = "RCPT to: <". $to. " > \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! =) Return "error message 7: $lastmessage". __line__;
DATA
$lastact = "data\r\n";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = 354) return "error message 8: $lastmessage". __line__;
Handling Subject Head
$head = "Subject: $subject \ r \ n";
$message = $head. " \ r \ n ". $message;
Processing from header
$head = "From: $from \ r \ n";
$message = $head. $message;
Process to Header
$head = "to: $to \ r \ n";
$message = $head. $message;
Plus End string
$message. = "\r\n.\r\n";
Send Message
Fputs ($fp, $message);
$lastact = "quit\r\n";
Fclose ($FP);
Error_log ("Send over------->ok!!", 0);
return true;
}
}
?>
/*
* php smtp Send mail Scoket class
* zhozphpsmtpsendmail.php
* Created on 2008/09/02 zhoz.com
* @author Zhoz
* v 1.72 update 2008/09/26 zhoz. Com
*/
Class Zhozphpsmtpsendmail {
Your SMTP server vendor, which can be a domain name or IP address
var $smtp = "";
SMTP requires an authentication value of 1, no authentication value of 0, and now most of the SMTP service providers have to verify, if not clear, contact your SMTP service provider.
var $check = 1;
Name of your email account
var $username = "";
Your e-mail password
var $password = "";
This email must be email on the sending server.
var $s _from = "";
/*
* Function: Initialization setting of sending letter
* $from the mailbox on your sending server
* $password your e-mail password
* $SMTP your SMTP server vendor, which can be a domain name or IP address
* $check SMTP requires authentication set to 1 does not require an authentication value of 0, now most of the SMTP service providers have to verify
*/
function Zhozphpsmtpsendmail ($from, $password, $smtp, $check = 1) {
if (Preg_match ("/^[^\d\-_][\w\-]*[^\-_]@[^\-][a-za-z\d\-]+[^\-") (\.[ ^\-][a-za-z\d\-]*[^\-]) *\. [A-za-z] {2,3}/", $from)) {
$this->username = substr ($from, 0, Strpos ($from, "@"));
$this->password = $password;
$this->smtp = $smtp? $SMTP: $this->smtp;
$this->check = $check;
$this->s_from = $from;
}
}
/*
* Function: Send mail
* $to Target Mailbox
* $from Source Mailbox
* $subject Mail Header
* $message Mail Content
*/
function Zhoz_send ($to, $from, $subject, $message) {
Connecting to a server
$fp = Fsockopen ($this->smtp, $errno, $ERRSTR, 60);
if (! $fp) return "failed to join Server". __line__;
Set_socket_blocking ($fp, true);
$lastmessage =fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! =) Return "error message 1: $lastmessage". __line__;
HELO
$yourname = "Yourname";
if ($this->check = = "1") $lastact = "EHLO". $yourname. " \ r \ n ";
else $lastact = "HELO". $yourname. " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = = fgets ($fp, 512);
if (substr ($lastmessage, 0,3)! =) return "error message 2: $lastmessage". __line__;
while (true) {
$lastmessage = fgets ($FP, 512);
if ((substr ($lastmessage, 3,1)! = "-") or (Empty ($lastmessage)))
Break
}
Identity verification
if ($this->check== "1") {
Validation begins
$lastact = "AUTH LOGIN". " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = 334) return "error message 3: $lastmessage". __line__;
User name
$lastact =base64_encode ($this->username). " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = 334) return "error message 4: $lastmessage". __line__;
User password
$lastact =base64_encode ($this->password). " \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = "235") return "error message 5: $lastmessage". __line__;
}
From:
$lastact = "MAIL from: <". $this->s_from. ">\r\n";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! =) Return "error message 6: $lastmessage". __line__;
To:
$lastact = "RCPT to: <". $to. " > \ r \ n ";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! =) Return "error message 7: $lastmessage". __line__;
DATA
$lastact = "data\r\n";
Fputs ($fp, $lastact);
$lastmessage = fgets ($FP, 512);
if (substr ($lastmessage, 0,3)! = 354) return "error message 8: $lastmessage". __line__;
Handling Subject Head
$head = "Subject: $subject \ r \ n";
$message = $head. " \ r \ n ". $message;
Processing from header
$head = "From: $from \ r \ n";
$message = $head. $message;
Process to Header
$head = "to: $to \ r \ n";
$message = $head. $message;
Plus End string
$message. = "\r\n.\r\n";
Send Message
Fputs ($fp, $message);
$lastact = "quit\r\n";
Fclose ($FP);
Error_log ("Send over------->ok!!", 0);
return true;
}
}
?>
Test method.
Run Code View Code copy code print about
/**
* zhozphpsmtpsendmail.php
* Created on 2008/09/02 zhoz.com
* PHP smtp Send mail class
* Instead of mail (): Because it's an error, I don't want to
*/
Here to configure the sending server information, if not changed can be used normally:
$from = ' zhoz@zhoz.com '; Your mailbox on the sending server
$password = ' zhoz '; Your e-mail password
$SMTP = ' smtp.zhoz.com '; Your SMTP server vendor, which can be a domain name or IP address
Class initialization
$zhoz _obj = new Zhozphpsmtpsendmail ($from, $password, $SMTP);
Send To start
$status = $zhoz _obj->zhoz_send ("zhoz008@126.com", "zhoz@zhoz.com", "Subject is zhoz", "Body is zhoz.com");
if ($status) {
Echo $status;
echo "No---------";
} else {
echo "Send OK-----------------! ";
Die
}
The result is, of course: send OK-----------------!
?>

http://www.bkjia.com/PHPjc/320576.html www.bkjia.com true http://www.bkjia.com/PHPjc/320576.html techarticle Copy the code as follows:? PHP/* * php smtp Send mail scoket class * zhozphpsmtpsendmail.php * Created on 2008/09/02 zhoz.com * @author zhoz * V 1.72 update 2008/09/26 zhoz. Com */...

  • 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.