FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
FORMfields v3 Tutorials
FORMfields Tutorials
FORMfields Lib Installation
FORMgen Installation
Manually Creating a Form
Load/Unload From a DB
Emailing a Form
Forms on Your Webpage
Creating Tables
Pagifying Data
Using CSS to Format Forms 1
Using CSS to Format Forms 2
Other Tutorials
Emailing a Form
Last Updated: September 19th, 2007
Sending an Email
Note: We will assume a subject of "Contact Us Submission" for the following examples.

To send an email with the contents of the form to info@mydomain.com, use:

    $ffForm->email("info@mydomain.com", "Contact Us Submission");

Adding a From Address
To send an email with the contents of the form from john@hotmail.com to info@mydomain.com, use:

    $ffForm->email("info@mydomain.com", "Contact Us Submission", "john@hotmail.com");

Adding Multiple Addresses
To send an email from john@hotmail.com and suzy@hotmail.com to peter@hotmail.com and mike@gmail.com, use:

    $ffForm->email("peter@hotmail.com,mike@gmail.com", "Contact Us Submission",
                     "john@hotmail.com,suzy@hotmail.com");

Sending Multiple Emails
To send separate emails to peter@hotmail.com and mike@gmail.com, use:

    $ffForm->email("peter@hotmail.com", "Contact Us Submission");
    $ffForm->email("mike@gmail.com", "Contact Us Submission");

Using an Entered Email Address
Let's say your form contains a field where a customer can enter his/her email address:

    $ffForm->addField(new EmailAddrField("email", "Email", FORM_FIELD_REQUIRED));

To send an email to this address, use:

    $ffForm->email($ffForm->getValue("email"), "Contact Us Submission");

To send an email to this address and mike@gmail.com, use:

    $ffForm->email($ffForm->getValue("email") . ",mike@gmail.com", "Contact Us Submission");

To send an email from this address and mike@gmail.com, use:

    $ffForm->email("info@mydomain.com", "Contact Us Submission",
                     $ffForm->getValue("email") . ",mike@gmail.com");

HTML Emails
With FORMfields, you can send customizable HTML emails and even attachments. The following example can be downloaded here.

    $to = "webmaster@yourdomain.com";
    $cc = "someone@yourdomain.com"; // optional
    $bcc = "someone@yourdomain.com"; // optional
    $from = $ffForm->getValue("email"); // optional

    $subject = "Contact Us Submission";

    // The msgHeader is the portion of text that preceeds the field values.
    $msgHeader = 
        "Dear Admin,<br /><br />"
        . "The following was submitted using your website:<br /><br />";

    // The msgFooter is the portion of text that follows the field values
    $msgFooter =
        "<br/>John Smith<br />"
        . "XYZ Company<br />"
        . "http://www.xyz.com<br />";

    // If you don't like the defaulted CSS styles, you can include another style sheet.
    $cssFile = "email.css"; // optional

    // You can include attachments by populating an array as follows.
    $attachments[0] = array("../calendar.gif", "calendar.gif"); // optional
    $attachments[1] = array("../palette.gif", "palette.gif"); // optional

    $useHtml = true;

    $ffForm->email($to, $subject, $from, $cc, $bcc, $msgHeader, 
              $msgFooter, $attachments, $useHtml, $cssFile);

The above example will yield an email that looks like:
Text Emails
Here is an example of how to send a text email:

    $to = "webmaster@yourdomain.com";

    $subject = "Contact Us Submission";

    // The msgHeader is the portion of text that preceeds the field values.
    $msgHeader = 
        "Dear Admin,\n\n"
        . "The following was submitted using your website:\n";

    // The msgFooter is the portion of text that follows the field values
    $msgFooter =
        "John Smith\n"
        . "XYZ Company\n"
        . "http://www.xyz.com\n";

    // You can include attachments by populating an array as follows.
    $attachments[0] = array("../calendar.gif", "calendar.gif"); // optional
    $attachments[1] = array("../palette.gif", "palette.gif"); // optional

    $useHtml = false;

    $ffForm->email($to, $subject, $from, $cc, $bcc, $msgHeader, 
              $msgFooter, $attachments, $useHtml, $cssFile);

Auto Responders Without Form Data
The following example illustrates how to send an auto responder email, without the form data, to the user who completed the form. The following example can be downloaded here.

    // Add an auto responder
    $mailForm = new FormForm();
    $responderTo = $ffForm->getValue("email");
    $responderSubject = "Contact Us Submission";
    $responderFrom = "webmaster@yourdomain.com";
    $responderCC = "someone@yourdomain.com"; // optional
    $responderBcc = "someone@yourdomain.com"; // optional
    $responderMessage =
        "Dear " . $ffForm->getValue("name") . ",<br /><br />"
        . "Thank you for completing our form.<br /><br />"
        . "John Smith<br />"
        . "XYZ Company<br />"
        . "http://www.xyz.com<br />";
    $mailForm->email($responderTo, $responderSubject, $responderFrom,
              $responderCC, $responderBcc, $responderMessage);

The above example will yield an HTML email that looks like:
Info
Support | Earn Money
Copyright © 2005-2018 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.