PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Question about the gform_autoresponder_email filter

  1. shaunkrd
    Member

    Hi,

    I have a project which requires a form to promote an event. The form needs to have fields for the submitter to provide details (name and email address) of up 10 friends to receive an email about the event. The user notification email will work nicely for this, but it would need to be customised and I can see the gform_autoresponder_email filter would allow me to send the email to addresses defined in the form.

    My question is can this filter (or another filter) be used to alter the content of the notification email according to the friend's details? Specifically to have "Dear [Friendname]" at the start of the email.

    If there is a suitable filter I can use then this plugin will be ideal for the project.

    Many thanks for your help,
    Shaun

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  2. You can use the gform_pre_submission_filter http://www.gravityhelp.com/documentation/page/Gform_pre_submission_filter to change the notification message completely before it's sent.

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  3. shaunkrd
    Member

    Hi Chris,

    Thanks for the reply. From that, I can see the autoResponder array which has a 'message' for manipulating the content of the user notification email.

    If my client adds in the content of the email through the plugin interface something like "Dear [friendname]", can I use this filter and properties to do a substring replace within 'message' to replace "[friendname]" with the data submitted in one of the form fields?

    Sorry that this is so specific, but I really appreciate your help.

    Thanks,
    Shaun

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  4. The problem is: there is one notification and it will be sent to all the recipients the same way. There is just one message sent to everyone. You need a way to send a unique message to everyone based on the name they submitted in the form, correct?

    I don't think the gform_pre_submission_filter will work in that case. You might have to do something custom with your user notifications. Maybe configure the notification in the form builder, then use the gform_after_submission hook to actually run a function which mails out individual notifications, based on the name submitted and the content of the $form['autoResponder']['message'] - you could loop through all the names submitted and replace the merge tag in the notification message yourself. Then use wp_mail() to send the actual notification.

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  5. shaunkrd
    Member

    Hi Chris,

    You need a way to send a unique message to everyone based on the name they submitted in the form, correct?

    Yes, this is right. In fact the email will be the same for everyone apart from the "Dear Name" part at the start.

    It sounds like there's probably enough scope for flexibility here to allow me to do what's needed, one way or another, so I'll try things out and see what works.

    Thanks very much for your input on this.
    Shaun

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  6. There is certainly a way to do it. I've done something similar and I would probably proceed just as I described. Set up the autoresponder message then process it after submission using the gform_after_submission hook, changing just the one merge tag (name) to each of the names submitted in the form, then use wp_mail() or phpMailer to send out the messages.

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink