Framework Helper PostEmail

Posted on Wednesday, October 28, 2009 in Documentation

/**
* @package Framework
* @subpackage helper
* @name PostEmail
* @version 1.0
*/

The PostEmail helper allows form elements to email without manual code or knowledge of PHP. Simply direct the form submission to the page with the PostEmail object. The PostEmail object will automatically email all form elements including names and values. A few configuration variables are required.

Here are the configuration variables that require attention:
define("POSTEMAIL_ADDRESS_FROM","auto@example.com");
define("POSTEMAIL_ADDRESS_TO","webmaster@example.com");
define("POSTEMAIL_SUBJECT","Email subject");
define("POSTEMAIL_ID_SEP","_");

Change the “auto@example.com” email address in the POSTEMAIL_ADDRESS_FORM value to the email address the server will label as the email sender. Change the “webmaster@example.com” email address in the POSTEMAIL_ADDRESS_TO value to the email address you would like the form data sent to. You can change “Email Subject” in the POSTEMAIL_SUBJECT value to what you would like the subject of the email to be. The POSTEMAIL_ID_SEP value is the character(s) used to fill whitespaces in the form element names; for example, a form element name might look like: name=”phone_number” id=”phone_number”. The POSTEMAIL_ID_SEP value is an underscore character so this character will be replaced with a whitespace when preparing the form elements for email. This means that “phone_number” will read “phone number” in the email (you can ignore this parameter, however, the constant POSTEMAIL_ID_SEP is required so do not remove it).

The PostEmail object runs ‘silent’ meaning all logic errors are suppressed. If you are having problems with the PostEmail object you can use a built in debugging tool like this:
$email_sent=$PE->sent();
The “$email_sent” variable will now contain a value of “null” (email was sent correctly) or a value of “error” (the email was not sent correctly).

Note: all form elements will be sent in the email, including elements like “submit” and “button”, so if you do not want these elements showing in the email simply remove the “name” attribute of the element.