About

Matthew Dilts is a Software and Web Application Developer from Cambridge Ontario with over 5 years of professional experience.

Contact Info
Get In Touch

Simple Email PHP Class

Simple Email PHP ClassThe Simple Email PHP Class makes sending email with PHP extremely easy.

The Simple Email PHP Class features a wide variety of options out of the box including:

  • Send HTML Type Emails
  • Send Plain Text Type Emails
  • Send Multi-Type Emails (HTML & Plain Text)
  • Easily add Attachments
  • Edit To, From, CC, and BCC fields easily
Usage Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$text = "This is a plain text message.";
$html = "<p>This is an <strong>HTML</strong> message.</p>";
 
$e = new Email();
$e->setTo('test@domain.com');
$e->setFrom('Matt Dilts <mattdilts@gmail.com>');
$e->setSubject('Test email');
$e->setAttachments('attach_1.jpg,attach_2.zip');
$e->setTextBody($text);
$e->setHtmlBody($html);
 
if($e->send())
	echo $e->printSource();
else	
	echo $e->getErrorMessage();
Alternate Usage
1
2
3
4
5
6
7
8
9
$text = "This is a plain text message.";
$html = "<p>This is an <strong>HTML</strong> message.</p>";
 
$e = new Email('test@domain.com', 'Matt Dilts <mattdilts@gmail.com>', 'Test Email', $text, $html, null, null, 'attach_1.jpg,attach_2.zip');
 
if($e->send())
	echo $e->printSource();
else	
	echo $e->getErrorMessage();
Function Reference
void $e->Email()
Description

Initialize Email class without setting options

Example

1
2
3
4
5
6
7
$e = new Email();
 
//set your options using the built-in functions
$e->setTo('test@domain.com');
$e->setFrom('mattdilts@gmail.com');
$e->setSubject('Test Email');
...
void $e->Email([ $args ])
Description

Initialize Email class by setting options by array or object.

Parameters

Parameter Type Description
$args (optional) array | object Assign configuration options by passing an array or object of options.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$args = array(
	'to' => 'test@domain.com',
	'from' => 'mattdilts@gmail.com',
	'subject' => 'Test Email',
	'textBody' => 'This is a plain text message.',
	'htmlBody' => '<p>This is an <strong>HTML</strong> message.</p>',
	'cc' => null,
	'bcc' => null,
	'attachments' => 'attach_2.jpg,attach_2.zip',
	'headers' => null,
	'replyTo' => null
);
 
$e = new Email($args);

or

1
2
3
4
5
6
7
8
9
10
11
12
13
$args = new stdClass;
$args->to = 'test@domain.com';
$args->from = 'mattdilts@gmail.com';
$args->subject = 'Test Email';
$args->textBody = 'This is a plain text message.';
$args->htmlBody = '<p>This is an <strong>HTML</strong> message.</p>';
$args->cc = null;
$args->bcc = null;
$args->attachments = 'attach_2.jpg,attach_2.zip';
$args->headers = null;
$args->replyTo = null;
 
$e = new Email($args);
void $e->Email([ $to [, $from [, $subject [, $text [, $html [, $cc [, $bcc [, $attachments [, $headers [, $replyTo ]]]]]]]]]])
Description

Initialize Email class setting options through arguments.

Parameters

Parameter Type Description
$to (optional) array | string Set the recipient or recipients of the email.
$from (optional) string Set the address to display in the “From” field of the email.
$subject (optional) string Set the subject line of the email.
$text (optional) string Set the plain text of a plain text type email.
$html (optional) string Set the HTML in an HTML or Multi-type email.
$cc (optional) array | string Set the address(es) to be carbon copied.
$bcc (optional) array | string Set the address(es) to be blind carbon copied.
$attachments (optional) array | string Set the file names of attachments to send with the email.
$headers (optional) array | string Set additional custom email headers.
$replyTo (optional) string Set the address to reply to.

Example

1
2
3
4
5
6
$text = "This is a plain text message.";
$html = "<p>This is an <strong>HTML</strong> message.</p>";
 
$e = new Email('test@domain.com', 'Matt Dilts <mattdilts@gmail.com>', 'Test Email', $text, $html, null, null, 'attach_1.jpg,attach_2.zip');
 
...
void $e->setTo($to)
Description

Example

void $e->setFrom($from)
Description

Example

void $e->setCC($cc)
Description

Example

$e->setBCC($bcc)
Description

Example

void $e->Subject($subject)
Description

Example

void $e->setTextBody($text)
Description

Example

void $e->setHtmlBody($html)
Description

Example

void $e->setAttachments($attachments)
Description

Example

void $e->setHeaders($headers)
Description

Example

void $e->setReplyTo($replyTo)
Description

Example

bool $e->send()
Description

Example

string $e->printSource()
Description

Example

string $e->getErrorMessage()
Description

Example