Example of sending an email using the pear: Net_SMTP class
Require 'net/SMTP. php ';
$ Host = '1970. com'; // ip address or domain name of the smtp server
- $ Username = 'arcow'; // username used to log on to the smtp server
- $ Password = 'secret'; // password used to log on to the smtp server
- $ From = 'jbxue @ 126.com '; // who sent the email
- $ Rcpt = array ('test @ test.com ', 'jbxue @ 126.com'); // multiple receivers can be set.
- $ Subj = "Subject: Who are you \ n"; // Subject
- $ Body = "test it"; // email content
/* Create a class */
- If (! ($ Smtp = new Net_SMTP ($ host ))){
- Die ("cannot initialize class Net_SMTP! \ N ");
- }
/* Start to connect to the SMTP server */
- If (PEAR: isError ($ e = $ smtp-> connect ())){
- Die ($ e-> getMessage (). "\ n ");
- }
/* Smtp Authentication Required */
- $ Smtp-> auth ($ username, $ password, "PLAIN ");
/* Set the sender's email address */
- If (PEAR: isError ($ smtp-> mailFrom ($ from ))){
- Die ("the sender's email address cannot be set to <$ from> \ n ");
- }
/* Set the recipient */
- Foreach ($ rcpt as $ ){
- If (PEAR: isError ($ res = $ smtp-> rcp1_( $ ))){
- Die ("the email cannot be delivered to <$ to>:". $ res-> getMessage (). "\ n ");
- }
- }
/* Start sending the email content */
- If (PEAR: isError ($ smtp-> data ($ subj. "\ r \ n". $ body ))){
- Die ("Unable to send data \ n ");
- }
/* Disconnect */
- $ Smtp-> disconnect ();
- Echo "sent successfully! ";
- ?>
|