# Forms - What is the best way to pass mailer arguments? - solved

**URL:** <https://discourse.getcockpit.com/t/forms-what-is-the-best-way-to-pass-mailer-arguments-solved/255>\
**Category:** Support\
**Created:** [September 10, 2018, 9:55am UTC](https://discourse.getcockpit.com/t/forms-what-is-the-best-way-to-pass-mailer-arguments-solved/255 "2018-09-10T09:55:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [September 10, 2018, 9:55am UTC](https://discourse.getcockpit.com/t/forms-what-is-the-best-way-to-pass-mailer-arguments-solved/255/1 "2018-09-10T09:55:48Z")

</div>

scenario:

My form has “name”, “mail”, “subject”, “message”, “some\_more” fields. I want to receive a mail in this form:

```auto
subject: [{{app.name}}] {{subject}}
reply_to: {{name}} <{{mail}}>
body: html template with {{message}} and all field contents
altMessage: pretty text message without HTML

```

The templating is no problem. I just have to pass the options anyhow.

A few days ago @artur added this useful trigger to the forms

`$this->app->trigger('forms.submit.before', [$form, &$data, $frm]);`

and he added the option to add `altMessage` to the mailer options. So I started to rewrite my [FormValidator addon](https://github.com/raffaelj/cockpit_FormValidation/tree/rewrite-trigger) to use the new features.

Well, it’s nice to validate or manipulate the submitted data, but there is no option to pass mailer options. If it would be like `[$form, &$data, $frm, &$options]`, I could manipulate everything I need.

While fiddling with the forms, I [repaired a bug](https://github.com/agentejo/cockpit/commit/ce7d261de6f53d7b040dca14020ea4c136a2b4be) to have mail subjects again, but I don’t like this solution. If I don’t want, that users can change the mail subject with a simple POST, I have to validate against it and send my own `$_REQUEST['__mailsubject'] = "..."` to have my custom subject. I think, it should be in `$options['mail_subject']`.

I didn’t understand, how to send the right csrf hash to use the inbuilt variant to pass form\_options through the api and actually, I don’t want to use it. It’s a security risk to give users the ability to change mailer settings.

Another way would be, to bypass the defaults

- by extending the forms and adding a new api endpoint or
- disable the inbuilt mailing and do the mailing inside my script from `forms.submit.before` or `forms.submit.after`.

But this doesn’t feel right.

I started a test repo with a few fixes [here](https://github.com/agentejo/cockpit/compare/next...raffaelj:fix_form-subject-and-form_options).

* * *

I [posted the same text](https://github.com/agentejo/cockpit/issues/853?_pjax=%23js-repo-pjax-container) 3 days before in the issues, because it felt more like an issue, than a support question. But now I think, that the forum is a better place to discuss such things.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [September 11, 2018, 9:30am UTC](https://discourse.getcockpit.com/t/forms-what-is-the-best-way-to-pass-mailer-arguments-solved/255/2 "2018-09-11T09:30:12Z")

</div>

This commit should solve your issues:

> <https://github.com/agentejo/cockpit/commit/a026081814ae306d6df274de43f6afd63430b428>
