Contact Me

    Here are the instructions on how to configure and use this contact form.

    1.  Install Contact Form 7
    2. Create a form that resembles the one below:

    3.  Now complete the “Mail” tab like this: This is the email that is sent to YOU.

    4.  Now complete the “Mail2” tab like this:  This is the email that will go to the CLIENT.

    5.  Add the code below to your functions.php file.  (be careful to pay attention that you put the code between the <?php and ?> tags that should already be in your functions.php file).

     

    // Add this function to the CF7 Hook before_send_email

    add_action( ‘wpcf7_before_send_mail’, ‘my_change_subject_mail’ );

    // This is the function the hook will execute

    function my_change_subject_mail($WPCF7_ContactForm)
    {
    $wpcf7 = WPCF7_ContactForm :: get_current() ;
    $submission = WPCF7_Submission :: get_instance() ;
    if ($submission)
    {

    // Get the data elements of submitted contact form (user, email address, body weight, etc.)
    $posted_data = $submission->get_posted_data() ;

    // If theres no data, just return
    if ( empty ($posted_data))
    return ;


    // This text will appear at the bottom of the email. Change it or remove it as you see fit.

    $mailFooter = “For more information, email me at <a href=’mailto: leromt@gmail.com’>leromt@gmail.com</a> or visit us at <a href=’http://mysite.com’>My Site</a>”;

    // Get the “mail_2” portion of the contact form so we can adjust it.

    $mail = $WPCF7_ContactForm->prop(‘mail_2’) ;


    $userWeightString = $posted_data[‘your-body-weight’];

    $userWeight = intval($userWeightString);

    /***************** DO ALL OF YOUR CALCULATIONS WITHIN THIS AREA *****************/

    $recommendedCalories = ($userWeight * 1.0) * 8.0;

    /**********************************************************************************/


    // Insert your calculations at the bottom of the body of the email to the user

    $mail[‘body’] .= “<h2>Based on your body weight (” . $userWeightString . “), I recommend you eat ” . $recommendedCalories . ” calories per day</h2>”;


    // Add the email footer AFTER you/’ve added your calculations
    $mail[‘body’] .= $mailFooter;

    // Save the email body
    $WPCF7_ContactForm->set_properties( array(“mail_2” => $mail)) ;


    return $WPCF7_ContactForm ;
    } // end if ($submission)

    } //end of my_change_subject_mail($WPCF7_ContactForm)

    6.  Create the page you want to have this contact form on and put the shortcode on that page.

    7.  You are done!