Use pear and PHP socket to send emails through SMTP Verification

Source: Internet
Author: User

 

Before the expiration time, I plan to do something that sends the registration information to the user's mailbox after the user registration is complete,
Put it in the space I rented in mvbb. Of course, I plan to implement it in PHP. However, PHP only carries a mail ().
Send an email. However, the premise of using mail () is to have a mail system (such as Qmail ). But in my rent
Generally, space is impossible. Can I use the account I registered at www.126.com, and then use the 126
What about SMTP sending? Simply using mail () is definitely not acceptable, because mail () does not provide an interface for verification.

Well, what should I do next. (Give me a try.Source code!! >_< !!)
Yes, SourceCodeAs follows:

<? PHP
Require_once 'mail. php ';

$ Conf ['mail'] = array (
'Host' => 'smtp .126.com ', // SMTP server address
'Auth' => true, // true indicates that the SMTP server needs to be verified, and false does not.
'Username' => 'liangbowen ', // User Name
'Password' => '******' // Password
);

// Send an email
$ Headers ['from'] = 'liangbowen @ 126.com '; // mail address
$ Headers ['to'] = 'liangbowen @ hotmail.com '; // recipient address
$ Headers ['subobject'] = 'test Mail Send by PHP bowen.mvbb.com '; // mail title
$ Mail_object = & mail: Factory ('smtp ', $ conf ['mail']);
// Body of the email
$ Body = "this is an email sent to you. ";

$ Mail_res = $ mail_object-> send ($ headers ['to'], $ headers, $ body); // send

If (Pear: iserror ($ mail_res) {// check the error
Die ($ mail_res-> getmessage ());
}
Else {
Echo "Send successful! ";
}

?>

As you can see, to use the socket and SMTP class of pear, you can download it from pear. Of course, you can also write SMTP and socket classes by yourself.

Pay source code: http://www.liangbowen.com/downloads/mail.zip

Because it is for learning reference, it is just a very simple example, and the file is also a bit messy.

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.