pentatonicfunk
5/9/2018 - 7:59 PM

Forminator Reply To

Forminator Reply To

<?php
add_filter( 'forminator_custom_form_mail_admin_message', 'my_forminator_custom_form_mail_admin_message', 10, 5 );
add_filter( 'forminator_custom_form_mail_user_message', 'my_forminator_custom_form_mail_user_message', 10, 5 );

function my_forminator_custom_form_mail_admin_message( $message, $custom_form, $data, $entry, $mailer ) {
	$MY_FORM_IDS = array( 540, 542 );
	$FROM_NAME   = 'Admin of Website';
	$FROM_EMAIL  = 'Adminof@Website.com';

	/**
	 * Need to get element-id,
	 * which can be acquired via inspect element, or
	 * on email message builder, click on `Form Data`
	 */
	$REPLY_TO_NAME  = $data['name-1'];
	$REPLY_TO_EMAIL = $data['email-1'];

	if ( empty( $REPLY_TO_NAME ) || empty( $REPLY_TO_EMAIL ) ) {
		return $message;
	}

	/**@var Forminator_Custom_Form_Model $custom_form */
	/**@var Forminator_CForm_Front_Mail $mailer */
	if ( in_array( (int) $custom_form->id, $MY_FORM_IDS, true ) ) {
		$mailer->set_headers(
			array(
				'From: ' . $FROM_NAME . ' <' . $FROM_EMAIL . '>',
				'Reply-To: ' . $REPLY_TO_NAME . ' <' . $REPLY_TO_EMAIL . '>',
				'Content-Type: text/html; charset=UTF-8',
			)
		);
	}

	return $message;
}

function my_forminator_custom_form_mail_user_message( $message, $custom_form, $data, $entry, $mailer ) {
	$MY_FORM_IDS = array( 540, 542 );
	$FROM_NAME   = 'Admin of Website';
	$FROM_EMAIL  = 'Adminof@Website.com';

	/**@var Forminator_CForm_Front_Mail $mailer */
	/**@var Forminator_Custom_Form_Model $custom_form */
	if ( in_array( (int) $custom_form->id, $MY_FORM_IDS, true ) ) {
		$mailer->set_headers(
			array(
				// remove Reply-To
				'From: ' . $FROM_NAME . ' <' . $FROM_EMAIL . '>',
				'Content-Type: text/html; charset=UTF-8',
			)
		);
	}

	return $message;
}