PHP Classes

Dead Simple Email: Compose and send email using text templates

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 191 All time: 8,581 This week: 74Up
Version License PHP version Categories
dead-simple-email 1.0.0GNU General Publi...5.3Email, PHP 5, Templates
Description 

Author

This class can compose and send email using text templates.

It can read a template message text from a file and process it replacing given variable values.

The class can send the processed text email message from a given sender, to a recipient address and with a given subject.

It can also configure additional message headers.

Picture of Eric Sizemore
  Performance   Level  
Name: Eric Sizemore is available for providing paid consulting. Contact Eric Sizemore .
Classes: 15 packages by
Country: United States United States
Age: 37
All time rank: 15119 in United States United States
Week rank: 180 Down22 in United States United States Down
Innovation award
Innovation award
Nominee: 4x

Winner: 2x

Example

<?php

/**
* @author Eric Sizemore <admin@secondversion.com>
* @package Dead Simple Email
* @link http://www.secondversion.com
* @version 1.0.0
* @copyright (C) 2014 Eric Sizemore
* @license
*
* Dead Simple Email free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

// ################################## HTML ##################################
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Dead Simple Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<script type="text/javascript" language="JavaScript">
<!--
function validate_form()
{
    var flag = true;
    var error_msg = 'The following errors occurred:\n';
    var sname = document.getElementById('sender_name');
    var semail = document.getElementById('sender_email');
    var smessage = document.getElementById('sender_message');

    // Check Name
    if (sname.value == '' || sname.value == null || sname.length < 2)
    {
        flag = false;
        error_msg += '\n Please enter your name';
    }

    // Check email
    if (semail.value == '' || semail.value == null)
    {
        flag = false;
        error_msg += '\n Please enter a valid email address';
    }

    // Check Message
    if (smessage.value == '' || smessage.value == null)
    {
        flag = false;
        error_msg += '\n Please enter a message';
    }

    if (!flag)
    {
        window.alert(error_msg + '\n\n');
    }
    return flag;
}
// -->
</script>
</head>

<body>

<div>
<?php

$result
= '';

// ################################################################
// Process the form and send the email..
if (!empty($_POST['submit']))
{
   
$name = filter_var($_POST['sender_name'], FILTER_SANITIZE_STRING);
   
$email = filter_var($_POST['sender_email'], FILTER_SANITIZE_STRING);
   
$message = str_replace("\r\n", "\n", $_POST['sender_message']);
   
$message = wordwrap(filter_var($message, FILTER_SANITIZE_STRING), 75);

    if (empty(
$name))
    {
       
$result .= 'Your name is required, please go back and enter your name.';
    }
    else if (empty(
$email))
    {
       
$result .= 'Your email is required, please go back and enter your email.';
    }
    else if (empty(
$message))
    {
       
$result .= 'A message is required, please go back and enter a message.';
    }
    else if (!
filter_var($email, FILTER_VALIDATE_EMAIL))
    {
       
$result .= 'Email is invalid. Please try again.';
    }
    else
    {
        require_once(
'./email.class.php');
       
$emailer = new emailer('email@domain.com', $email, 'Test Email');
       
$emailer->use_template(array(
           
'name' => $name,
           
'email' => $email,
           
'ip' => $_SERVER['REMOTE_ADDR'],
           
'message' => $message
       
), 'example.tpl');

        if (
$emailer->send())
        {
           
$result .= "Thank you, $name, your enquiry was sent.";
        }
        else
        {
           
$result .= 'Seems to have been a problem sending the email. Please try again.';
        }
    }
?>
<p><?php echo $result; ?></p>
<?php
}
else
{
?>
<h1>Contact</h1>
    <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" style="display: inline;" onsubmit="return validate_form();">
    <table border="0" cellpadding="2" cellspacing="1">
    <tbody>
    <tr>
        <td><label for="sender_name">Name:*</label></td>
        <td><input type="text" name="sender_name" id="sender_name" maxlength="100" /></td>
    </tr>
    <tr>
        <td><label for="sender_email">E-mail:*</label></td>
        <td><input type="text" name="sender_email" id="sender_email" maxlength="100" /></td>
    </tr>
    <tr>
        <td valign="top"><label for="sender_message">Message:*</label></td>
        <td><textarea name="sender_message" id="sender_message" rows="4" cols="35"></textarea></td>
    </tr>
    <tr>
        <td colspan="2" align="center"><input type="submit" name="submit" value="Submit" /></td>
    </tr>
    </tbody>
    </table>
    </form>
<?php
}

?>
</div>

</body>
</html>


  Files folder image Files (4)  
File Role Description
Plain text file email.class.php Class Main class file.
Accessible without login Plain text file example.php Example Example form script that makes use of the class.
Accessible without login Plain text file example.tpl Data Example email template file.
Accessible without login Plain text file license.txt Lic. License information.

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:191
This week:0
All time:8,581
This week:74Up