Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created December 7, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/710b44a8f928d304c7af56a9887f842e to your computer and use it in GitHub Desktop.
Save Shelob9/710b44a8f928d304c7af56a9887f842e to your computer and use it in GitHub Desktop.
Examples of using the caldera_forms_mailer filter. See https://calderaforms.com/doc/caldera_forms_mailer/
<?php
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) {
//MAKE SURE TO CHANGE FORM ID
if( 'CF1243hiMatt' == $form[ 'ID' ] ) {
//$data has all of the field data for submission
//change this to your field ID
$field_id = 'cf1234hiKevin';
if( ! empty( $data[ $field_id ] ) ){
//create temporary file, see: http://php.net/manual/en/function.tmpfile.php
$temp_file = tmpfile();
//write field value to that file
fwrite( $temp_file, $data[ $field_id ] );
$mail[ 'attachments' ][] = $temp_file;
}
}
return $mail;
}, 10, 3 );
<?php
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) {
//MAKE SURE TO CHANGE FORM ID
if( 'CF1243..' == $form[ 'ID' ] ) {
//$data has all of the field data for submission
//Presuming that fld1235 is name.
//Presuming that fld54321 has a post ID for a post with useful meta data, like a phone number for a store location.
$name = $data[ 'fld1235' ];
$id = $data[ 'fld54321' ];
$phone_number = get_post_meta( $id, 'phone_number', true );
$message = "Thanks for getting in touch {$name} we will get back to you soon. If you have immediate questions, the phone number for our closest store is {$phone_number}.";
$mail[ 'message' ] = $message;
}
return $mail;
}, 10, 3 );
<?php
add_filter( 'caldera_forms_mailer', function( $mail, $data, $form ) {
//MAKE SURE TO CHANGE FORM ID
if( 'CF1243..' == $form[ 'ID' ] ) {
$mail[ 'recipients' ][] = 'luke@skywalker.com';
}
return $mail;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment