 [ ← blog / class ](/) Nov 24, 2011  ·  \#class  ·  1 min read 

# PHP Mail Class



 Mailer is a PHP class to help provide easier use of the PHP mail() function and error support. In all other of my scripts using the mail() function I would have lines upon lines of code just to make sure every thing sent right and provide my own error checking. This helps cut down on that process. Check out the Mailer [side page for a detailed break down on how it works](http://glamanate.com/playground/Mailer/ "Mailer PHP Class"), or just look at the example below for a pretty self explanatory usage. 

```
<?php

$mymail = new Mailer('receiver@domain.com');
//From() is optional, can be defined within class manually
$mymail->From('Name', 'email@domain.com');

$mymail->Subject('Test email');
$mymail->Message('Tester');
if(!$mymail->Send()) {
echo $mymail->Error();
} else {
echo 'It worked!';
}

?>
```

You can download the [Mailer PHP Class source files](http://glamanate.com/playground/Mailer/Mailer.zip "Mailer PHP Class Source Code"). 

  ![](/themes/custom/mglaman/images/headshot.webp)Thanks for reading

I write about Drupal, PHP, and the quiet infrastructure behind large sites — caching, config, and testing. New posts land every week or two.

 [Subscribe via RSS →](/rss.xml) [About me →](/about-me) 

 



 

  [← Older

PHP Server Variables

 ](/blog/php-server-variables) [Newer →

EasyPHP - WAMP environment

 ](/blog/easyphp-wamp-environment)