JamesDDunn

Gravity Forms - Send Personalized Notification Emails

Mar 5th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. // Send personalized emails from list field
  2.  
  3. add_action( 'gform_after_submission_1', 'send_list_field_notifications', 10, 2 );
  4. function send_list_field_notifications( $entry, $form ) {
  5. $field_id = 19; // the id of the list field
  6.  
  7. // get the $field object for the provided id
  8. $field = RGFormsModel::get_field( $form, $field_id );
  9.  
  10. // check the field type as we only want the rest of the function to run if the field type is list
  11. if ( $field->get_input_type() != 'list' ) {
  12. return;
  13. }
  14.  
  15. $list_values = rgar( $entry, $field_id );
  16.  
  17. if ( empty( $list_values ) ) {
  18. return;
  19. }
  20.  
  21. // setup the basic notification properties
  22. $notification = array(
  23. 'id' => 'list_field_notification',
  24. 'name' => 'list_field_notification',
  25. 'fromName' => '{Your Name (First):16.3} {Your Name (Last):16.6}',
  26. 'from' => '{Your Email Address:7}',
  27. 'subject' => 'Our Team ({Team Name:1}) Has Been Registered in The Reach Open Golf Tournament',
  28. );
  29.  
  30. $message = 'Hey {firstname},<br><br>I just registered our team ({Team Name:1}) in the 2016 Reach Open Golf Tournament. Be sure to register as a member of our team by visiting the website at: http://thereachopen.org/register-with-a-team/. [gravityforms action="conditional" merge_tag="{Do You Wish To Pay For Your Entire Team Or Will Each Member Pay Individually:4}" condition="is" value="Pay For Entire Team"][gravityform action="conditional" merge_tag="{Buy Team Tee Buster & Mulligans:13.1}" condition="is" value="I would like to pay for my team\'s Tee Buster and Mulligans"]
  31. I have already paid our team registration costs of $500 as well as purchased a Tee Buster and Mulligan package for each of us, so you will only have to register as a member of our team.
  32. [/gravityform][/gravityforms][gravityforms action="conditional" merge_tag="{Do You Wish To Pay For Your Entire Team Or Will Each Member Pay Individually:4}" condition="is" value="Pay For Entire Team"][gravityform action="conditional" merge_tag="{Buy Team Tee Buster & Mulligans:13.1}" condition="isnot" value="I would like to pay for my team\'s Tee Buster and Mulligans"]
  33. I have already paid our team registration costs of $500. If you would like to purchas a Tee Buster and Mulligan package you can choose that from the registration form. So go ahead and register as a member of our team.
  34. [/gravityform][/gravityforms][gravityforms action="conditional" merge_tag="{Do You Wish To Pay For Your Entire Team Or Will Each Member Pay Individually:4}" condition="is" value="Pay For Entire Team"]When you register, you will need to pay your registration fee of $125. You may also purchase a Tee Buster and Mulligan package at that time.
  35. [/gravityforms]<br>
  36. <br>
  37. While you are registering, if you want to attend the dinner that evening, you can make your reservations and pay for that.<br>
  38. <br>
  39. You will be taken to PayPal to pay any additional fees after you click the submit button if you select "Pay Online". If you choose to mail in a check, you will be shown the mailing address to send the check to.<br>
  40. <br>
  41. [gravityforms action="conditional" merge_tag="{My Personal Note:17}" condition="isnot" value=""]
  42. P.S. {My Personal Note:17}
  43. [/gravityforms]';
  44.  
  45. $first_name_col_key = rgars( $field->choices, "0/text" ); // first column
  46. $email_col_key = rgars( $field->choices, "2/text" ); // third column
  47.  
  48. $list_values = unserialize( $list_values );
  49.  
  50. foreach ( $list_values as $value ) {
  51. // get the emails for each row
  52. $email = rgar( $value, $email_col_key );
  53. if ( GFCommon::is_valid_email( $email ) ) {
  54. $notification['to'] = $email;
  55. $notification['message'] = str_replace( '{firstname}', rgar( $value, $first_name_col_key ), $message );
  56. GFCommon::send_notification( $notification, $form, $entry );
  57. }
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment