PHP Classes

File: emailer_sample.php

Recommend this page to a friend!
  Classes of Dean Newman   Emailer   emailer_sample.php   Download  
File: emailer_sample.php
Role: Example script
Content type: text/plain
Description: Sample File
Class: Emailer
Send messages with attachment files via SMTP
Author: By
Last change:
Date: 12 years ago
Size: 1,435 bytes
 

Contents

Class file image Download
<?php
/**
 * Sample File
 *
 * This class is used to construct email messages using the MIME protocol
 * it also has full attachment and additional header support.
 *
 * @author Dean Newman < db_newman@hotmail.com >
 * @license GNU/General Public License v2 (GPL)
 * @copyright Copyright 2012, Dean Newman
 */

include 'class_emailer.php';

$emaildata = array(
   
'from' => 'sender@example.com',
   
'from_name' => 'From Name',
   
'to' => 'recipient@example.com',
   
'to_name' => 'Recipient Name',
   
'subject' => 'Sample Message',
   
'body' => 'This is the message content',
   
'attach' => __FILE__
   
'attachas' => __FILE__ . '.txt'
);

$email = new emailer();
// Enables SMTP emulation
//$email->smtp_configure('username', 'password', 'server', 'port');

// Validate the email addresses
if ( !$email->validate($emaildata['from']) || !$email->validate($emaildata['to']) )
{
    die(
'Invalid email address');
}

// Construct the email


$email->set_recipients($emaildata['to'], $emaildata['to_name']);
// Associative array also available:
//$email->set_recipients(array($emaildata['to_name'] => $emaildata['to']));

$email->set_sender($emaildata['from'], $emaildata['from_name']);

$email->set_data($emaildata['subject'], $emaildata['body']);

$email->attach_file($emaildata['attach'], $emaildata['attachas']);

if ( !
$email->send() )
{
    die(
'Unable to send');
}
else
{
    die(
'Sent!');
}

?>