Forminator: Autopulate email field

I'm using Forminator Pro to gather "contact us" inquiries from a website, but I'm looking to make the "form" field populated by the address of the person completing the form, rather than the website it's come from.

So when I receive the form, the "form" field in the email is the customer's email, rather than the address from which the form was sent on the website.

In this case, if I filled in the form and entered my email address as name@site.co.uk, I'd like the form to appear as from that address, rather than noreply@site.co.uk.

Is this possible?

  • Tony G

    +1 for a hook on every field to substitute the value, before and after entry.

    Examples:
    - Entry of name of Responsible party can be defaulted with the name of the current user. We need an initial_form_display filter on the form so that we can pre-populate First Name and Last Name, and Email with data from the current user. We might also need to go to some CPT to retrieve a default Primary Phone field.
    - After entry of a field like Email, we need a post-entry filter, so that, if the user cleared this required field, we might be able to repopulate with the current user's email.

    • Tony G

      Zach we're on the same page with the priority on the Forminator request. But I believe the email situation is a sort of self-induced wound. If your client wants specific functionality, they need to provide the resources to make it possible. That means using a real address in their case for various purposes, whether for reply-to, bounce notices, unsubscribe, support, or other functions. If that involves their IT, so be it. That's their additional complication - and your time should be on the clock that you spend trying to make things work despite their internal complications. HTH

  • Tony G

    Guy - I'm looking back at your OP, where I think all instances of the word "form" should be substituted with "FROM". Are you asking for emails created by Forminator to have the FROM field set to the address of the person who completed the form?

    There are a few ways to resolve this, all of which require some custom code but they will accomplish what you want without WPMU DEV having to make changes.

    1) Hook the email process, intercept emails from Forminator, and modify addresses there.
    2) Manually insert one line, apply_filters, into Forminator right before it sends the email. Hook that filter and substitute your own details.
    3) Send emails to an email processor, reformat it and send it out with new details.

    There's one big issue with this whole thing. SMTP servers should not be sending emails with random From tags! My email server won't let me send From foo@bar.tld when I login as myname@mydomain.tld. What you're proposing is quite spammy and I believe many email clients and filters will reject these transactions.

    Perhaps you could explain your application and wishes. From a business perspective we might be able to convince you that what you're asking is not good for your business - which would preclude the technical solution. Or we might better understand what you ultimately want to do so that we can suggest a better way to accomplish your business objectives.

    • Guy

      My typos in the OP are horrific. Sorry, it's confused my message!

      So your assumption is correct, I'm looking for the FROM field to be set to the individual who has completed the form. I understand that it is bad practice, however this is only internally used. It is to feed enquiries directly into LiveZilla and facilitates simple responses back to our customer from there.

      If the form, when completed, is sent from our@website.co.uk, when the ticket is automatically created in LiveZilla, the details are logged with our website name and our email address and replies must then be amended to reflect the customer's name and email address.

      So while under normal circumstances, this practice would be sloppy and frowned upon, this precise requirement is the why I need this alteration.

  • Panos

    Hi Guy ,

    For changing the email in the FROM header, you can use the wp_mail filter. Here is an example for how to use in headers that Forminator creates by default:

    add_filter( 'wp_mail', function( $mail_args ){
    
    	if( ! isset( $_REQUEST["action"] ) || "forminator_submit_form_custom-forms" != $_REQUEST["action"] ){
    		return $mail_args;
    	}
    
    	if ( isset( $mail_args['headers'] ) && is_array( $mail_args['headers'] ) ) {
    
    		foreach ( $mail_args['headers'] as $key => $header_item ) {
    			if ( substr( $header_item, 0, 6 ) === "From: " ) {
    				$header_item = preg_replace( "~\<(.+?)\>~", '<our@website.co.uk>', $header_item );
    				$mail_args['headers'][$key] = $header_item;
    				break;
    			}
    		}
    
    	}
    
    	return $mail_args;
    
    }, 30 );

    I am not sure what exactly you need to replace. The above snippet should replace the email in the FROM header with our@website.co.uk

    If this is not what you are looking for could you please be more specific?

    Kind regards

    • Guy

      Thanks for your reply Panos.

      I want the email which contains the details submitted on the form to appear to come from the email address the customer entered into a form.

      John Smith completes a form. He enters all his details including his email address john@smith.co.uk. The form details are emailed into us and the form is sent from "our@website.co.uk" which is then processed by LiveZilla, and a ticket automatically created. In order for operators to respond to that ticket by email, they have to manually enter the email address on each ticket, because the email out of Forminator is always from "our@website.co.uk".

      I want to decide on the name and email address from which the email submission is sent. Simply put.

      This is a feature of NinjaForms and other form plugins, and I would like the ability to set this pretty easily, as other plugins do. Forminator is lacking this in my eyes.

  • Panos

    Hi Guy ,

    Thanks for clarification :slight_smile:

    I see why you need this, I'm not sure this feature has been requested before, but I'll mark this as a feature request.

    For now you can modify the snippet to:

    add_filter( 'wp_mail', function( $mail_args ){
    
    	$email_field = 'email-1';
    
    	if( ! isset( $_REQUEST["action"] ) || "forminator_submit_form_custom-forms" != $_REQUEST["action"] || ! isset( $_POST[ $email_field ] ) ){
    		return $mail_args;
    	}
    
    	if ( isset( $mail_args['headers'] ) && is_array( $mail_args['headers'] ) ) {
    
    		$new_from = $_POST[ $email_field ];
    
    		foreach ( $mail_args['headers'] as $key => $header_item ) {
    			if ( substr( $header_item, 0, 6 ) === "From: " ) {
    				$header_item = preg_replace( "~\<(.+?)\>~", '<'. $new_from .'>', $header_item );
    				$mail_args['headers'][$key] = $header_item;
    				break;
    			}
    		}
    	}
    
    	return $mail_args;
    
    }, 99 );

    Hope this helps :slight_smile:

  • James Morris

    Hello Guy

    I hope you don't mind me jumping in here...

    You can add the code to your active theme's functions.php file or you if you want to ensure the code works regardless of themes, you can create a MU Plugin and upload it to wp-content/mu-plugins/ so that it is forced to execute regardless of which theme is active. You can learn more about how to create a simple MU Plugin on the WordPress Codex here -> https://codex.wordpress.org/Must_Use_Plugins

    I hope this clarifies a bit.

    Best regards,

    James Morris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.