Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanHerman/bab8f683681211a6ce02 to your computer and use it in GitHub Desktop.
Save EvanHerman/bab8f683681211a6ce02 to your computer and use it in GitHub Desktop.
Easy Forms for MailChimp - Email notifications when a user signs up
<?php
/*
* This snippet should go at the bottom of your functions.php file.
* Send a notification email to the user after a form is successfully submitted
* @sample snippet
*/
function yikes_easy_forms_for_mailchimp_email_notifications( $email, $submitted_data, $form, $notifications ) {
if( ! empty( $submitted_data ) ) {
// add additional items you don't want included in the email notification
$exclude_from_email = array(
'yikes-mailchimp-honeypot',
'yikes-mailchimp-associated-list-id',
'yikes-mailchimp-submitted-form',
);
$email_body = '<p>Sweet, It looks like a new user submitted our form!</p>';
// loop over the form data
foreach( $submitted_data as $merge_var => $submitted_data ) {
if( ! in_array( $merge_var, $exclude_from_email ) ) {
// convert the optin time to a more readable format
$email_body .= ( $merge_var == 'optin_time' ) ? '<strong>Optin Time:</strong> ' . date( 'M jS, Y', strtotime( $submitted_data ) ) . ' at ' . date( 'h:i a', strtotime( $submitted_data ) ) : '<strong>' . $merge_var . '</strong>: ' . $submitted_data . '<br />';
}
}
// append our celebratory picture
$email_body .= '<img src="http://www.cakemall.in/Blog/wp-content/uploads/2015/07/party.jpg" style="width:350px;display:block;margin:0 auto;" />';
// add all the emails you want to receive this notification, to this array
$recipients = array(
'your-email@example.com' // Swap this out for your email!!
);
$subj = 'New Easy Forms for MailChimp Submission';
// set the email to HTML
add_filter( 'wp_mail_content_type', function( $content_type ) {
return 'text/html';
});
wp_mail( $recipients, $subj, $email_body );
}
return $email;
}
add_action( 'yikes-mailchimp-form-submission', 'yikes_easy_forms_for_mailchimp_email_notifications', 10, 4 );
?>
@estarlight
Copy link

Not a developer here (though I have a github account from taking a few freecodecamp classes). Came across this while googling how to get an email notification for form submissions with the Easy Forms plugin. Can I copy and paste this into the functions.php section in the Editor in WordPress or will that completely break my site?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment