Forums

WordPress Form Manager
Making an Email form with more than one reply:to's (5 posts)

  1. Anthony
    Member
    Posted 1 year ago #

    I was wondering if it was possible to have the form allow to send to multiple users. Like in a contact form, They could choose which department they wanted to contact.

    [sales]
    [general inquries]
    [refunds]

    All three above would have different email address. Would this be possible in making this form manager into a replaceable contact form as well? I also don't want the email address to be shown of course for spamming reasons.

  2. hoffcamp
    Member
    Plugin Author

    Posted 1 year ago #

    The best way would be to hook into the 'fm_form_submission' action. This is something I added recently. You can use the template here so that updates to form manager don't overwrite your changes. Just modify the code and upload it as a new plugin.

    So here are the details:
    1) Give the list item a nickname, 'email-list'. For now I'll assume the list has the items 'Sales', 'General', 'Refunds'.
    2) Inside the fm_custom_submission_action function, put the following:

    global $fm_display;
    
    	$formInfo = $args['form'];
    	$postData = $args['data'];
    
    	$subject = fm_getSubmissionDataShortcoded($formInfo['email_subject'], $formInfo, $postData);
    	$message = $fm_display->displayDataSummary('email', $formInfo, $postData);
    	$headers  = 'From: '.fm_getSubmissionDataShortcoded($formInfo['email_from'], $formInfo, $postData)."\r\n".
    				'Reply-To: '.fm_getSubmissionDataShortcoded($formInfo['email_from'], $formInfo, $postData)."\r\n".
    				'MIME-Version: 1.0'."\r\n".
    				'Content-type: text/html'."\r\n";

    This code will load the e-mail settings for the current form, basically just the 'Subject' and 'From' fields as you have them set in the form editor. You could replace these with whatever you want, but make sure to keep the MIME-Version and Content-type parts in the $headers variable or else you won't be able to have HTML in the message body.

    3) Add the following to the end of the same function:

    $addressArray = array(
    		'Sales' => "user@user.com",
    		'General' => "user2@user.com",
    		'Refunds' => "somebody@something.com",
    	);
    
    	fm_sendEmail($addressArray[$postData['email-list']], $subject, $message, $headers);

    This is the key part, where you specify an e-mail address to send to based on the value of the 'email-list' item. Make sure to put a comma after each item in the $addressArray variable like in the example.

    Good luck!

  3. NyToRo
    Member
    Posted 1 year ago #

    For your help, your time, your plugin, your work : Mr Campbell Hoffman, THANKS YOU !!!!

  4. diveshsareen
    Member
    Posted 10 months ago #

    Hi can I please ask which file do we have to add the code in please. Thanks.

  5. hoffcamp
    Member
    Plugin Author

    Posted 10 months ago #

    If you read my first post in this thread, I linked to a plugin you can install on your site. The plugin is a template for a custom submission action. That is where the code goes.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic