PHP online mail sending class, sent through SMTP

Source: Internet
Author: User
? /** Email sending class * author: many Cainiao * Contact Email: kingerqATmsnDOTcom * founded at: * Note: This class is modified, forgot the source */classsmail {// your SMTP server supplier, which can be a domain name or IP address /*
* Mail sending class
* Author: many Cainiao
* Contact Email: kingerq AT msn DOT com
* Created:
* Note: This type is converted and the source is forgotten.
*/
Class smail {
// Your SMTP server supplier, which can be a domain name or IP address
Var $ smtp = 'smtp .163.com ';
// SMTP requires authentication. if the value is set to 1, no authentication value is 0. Currently, most SMTP service providers must verify the value. if you do not understand the value, contact your smtp service provider.
Var $ check = 1;
// Your email account name
Var $ username = '';
// Your email password
Var $ password = '';
// This email must be an email sent to the server.
Var $ s_from = '';
 
/*
* Function: Mail initialization settings
* $ From the email address on your sending server
* $ Password your email password
* $ Smtp your SMTP server supplier, which can be a domain name or IP address
* $ Check SMTP requires authentication. if the value is set to 1, no authentication is required. Currently, most SMTP service providers must verify the value.
*/
Function smail ($ 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 an email
* $ To target email address
* $ From Origin email
* $ Subject Mail title
* $ Message Content
*/
Function send ($ to, $ from, $ subject, $ message ){
 
// Connect to the server
$ Fp = fsockopen ($ this-> smtp, 25, $ errno, $ errstr, 60 );
If (! $ Fp) return 'connection to server failed'. _ LINE __;
Set_socket_blocking ($ fp, true );

$ Lastmessage = fgets ($ fp, 512 );
If (substr ($ lastmessage, 0, 3 )! = 220) return 'error message: '. $ 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 )! = 220) return 'error message $ lastmessage'. _ LINE __;
While (true ){
$ Lastmessage = fgets ($ fp, 512 );
If (substr ($ lastmessage, 3,1 )! = '-') Or (empty ($ lastmessage )))
Break;
}
 

// Authentication
If ($ this-> check = '1 '){
// Verification start

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.