Advertisement
phpaddict

Simple mail class

Jul 10th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. The email class:
  2.  
  3. <?php
  4. /**
  5.  * mail.php
  6.  *
  7.  * A (very) simple mailer class written in PHP.
  8.  *
  9.  * @author Zachary Fox
  10.  * @version 1.0
  11.  */
  12.  
  13. class ZFmail{
  14.     var $to = null;
  15.     var $from = null;
  16.     var $subject = null;
  17.     var $body = null;
  18.     var $headers = null;
  19.  
  20.      function ZFmail($to,$from,$subject,$body){
  21.         $this->to      = $to;
  22.         $this->from    = $from;
  23.         $this->subject = $subject;
  24.         $this->body    = $body;
  25.     }
  26.  
  27.     function send(){
  28.       $this->addHeader('From: '.$this->from."\r\n");
  29.         $this->addHeader('Reply-To: '.$this->from."\r\n");
  30.         $this->addHeader('Return-Path: '.$this->from."\r\n");
  31.         $this->addHeader('X-mailer: ZFmail 1.0'."\r\n");
  32.         mail($this->to,$this->subject,$this->body,$this->headers);
  33.     }
  34.  
  35.     function addHeader($header){
  36.         $this->headers .= $header;
  37.     }
  38.  
  39. }
  40. ?>
  41.  
  42. The usage example:
  43.  
  44. <?php
  45. /**
  46.  * example/mail.php
  47.  *
  48.  * An example script to accept a post and send an email using ZFmail.
  49.  *
  50.  * @author Zachary Fox
  51.  */
  52.  
  53.  // Include the mail.php file that holds the class definition
  54.  require_once('mail.php');
  55.  
  56.  // First we set the to address. I would not let anyone put in a to
  57.  // address in a web form, and neither should you.
  58.  $to = 'me@example.com';
  59.  
  60.  // Then we get the information we need from the $_POST array.
  61.  // This step is not necessary, but in a production environment,
  62.  // we would process and sanitize this data here, rather than
  63.  // passing raw post data to the class.
  64.  $from = $_POST['from'];
  65.  $subject = $_POST['subject'];
  66.  $body = $_POST['body'];
  67.  
  68.  // Then create the ZFmail object using the information from above
  69.  $mail = new ZFmail($to,$from,$subject,$body);
  70.  
  71.  // Finally, call the object's send method to deliver the mail.
  72.  $mail->send();
  73. ?>
  74.  
  75. Taken from http://www.zacharyfox.com/blog/php/simple-mail-class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement