Use PEAR and PHP Socket to implement email via SMTP verification

xiaoxiao2021-03-06  41

I plan to do one - I plan to do one - the user registered after the registration information to the user's mailbox, put it in the space I rented in the MVBB. Of course I am planning PHP implementation. However, PHP itself has only a mail () used to send an email. However, it is necessary to have a mail system (qmail A) with mail (). But in the general space I rented, it is impossible. Can you use the account that I registered at www.126.com and send it with 126 SMTP? It is definitely not available to mail () because Mail () does not provide verification interface.

Ok, what should I do. (Less waste, give the source code !!> _

$ conf ['mail'] = array ('host' => 'SMTP.126.com', // SMTP server address 'auth' => true, // true means that the SMTP server needs to be verified, FALSE does not need 'username' => 'LiangBowen', // User Name 'Password' => ****** '// Password);

// Send an email $ headers ['from'] = 'liangbowen@126.com'; // Sending address $ headers ['to'] = 'liangbowen@hotmail.com'; // Receive address $ headers [' Subject '] =' Test mail send by php bowen.mvbb.com '; // message title $ mail_object = & mail :: Factory (' SMTP ', $ conf [' mail '); // message body $ body = " This is an email sent to yourself. "

$ mail_res = $ mail_object-> send ($ Headers ['To'], $ Headers, $ Body); // Send

IF (Pear :: ISERROR ($ mail_res)) {// detection error DIE ($ mail_res-> getMessage ());} else {echo "send successful!";

?>

As you can see, use the PEAR's socket and SMTP classes, you can go to PEAR to download. Of course, you can also write SMTP and Socket classes 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 there are some chaos.

转载请注明原文地址:https://www.9cbs.com/read-71941.html

New Post(0)