Form Module email subject
Hi
I am using the forms module in a site and want to make the subject line of each email to be unique to that email. This prevents the mail form getting attached to others emails (google apps) in the inbox.
The forms module is been used as a contact form. I have been able to add a datetime() to the subject in the config/forms.php file and that works great.
I'd like to be able to add the senders name too so that the emails are easily identified in the google mail inbox list.
Can anyone please explain how this might be done via the CMS where the form is created.
Thanks
Comments
<?=form('contact')?>
The forms.php config file has a default 'email_subject' line and 'email_from' parameter that is for all forms, however, you can specify it at the form level as well:
<?=form('contact', array('email_subject' => 'My subject line...'))?>
However I altered the function in Fuel_Forms.php to
protected function get_email_subject() { if (empty($this->email_subject)) { return $this->fuel->forms->config('email_subject'); } $email_subject = str_replace(array('{{', '}}'), array('{', '}'), $this->email_subject); $output = parse_template_syntax($email_subject, $_POST, TRUE); return $output; //return $this->email_subject; }
This allows me to add a email subject line via the CMS for that form with {{name}} template tag so that it's parsed with the $_POST['name'] value
It's a hack to the core forms code and Im sure theres a better way to do this...
1. Create a hook function and place it your fuel/application/helpers/my_helper.php like so:
function my_form_post_process($form) { $form->email_subject = 'This is a TEST!!!'; }
2. Then in your fuel/application/config/forms.php, add the following to your $config['forms']['forms']['my_form'] where my_form is the name of your form:
$config['forms']['forms'] = array( 'my_form' => array( // ..... additional config stuff goes here 'hooks' => array('post_process' => 'my_form_post_process'), ) );
i set it up as you have above but changed the my_form to contact
It looks like that the hook added to the config>forms.php file is not been added to $hooks on the form object.
I added it manually into
protected $hooks = array('post_process' => 'my_form_post_process');
in the Fuel_forms.php file and your example above works and changes the email subject to: This is a TEST!!!
Any further help would be appreciated.
$this->call_hook('post_process');