Forms: Add subject, CC and BCC

Hi guys, can anyone tell me how to add custom subject for the mail coming from the forms. I’ve tried in config.yaml in mailer section, but nothing happens. Same with cc and bcc. Other settings, such as from, from_name, transport, host, etc. works just fine, as it is in the documentation.

Thanks in advance!

P.S. I am using “Next” branch, as of today.

There is a bug for the mail subject. I currently think about/work on it.

Adding dynamic cc and bcc through the forms settings is complicated right now…

If you want to adjust cc and bcc in config.yaml, you have to write these options as an array:

# use smtp to send emails
mailer:
    from      : contactform@example.com
    transport : smtp
    host      : smtphost.provider.com
    user      : fancy-username
    password  : SuperSavePassword
    port      : 587
    auth      : true
    encryption: starttls
    cc        :
        support@example.com
    bcc       :
        admin@example.com

It’s fixed now. See this thread for more informations: Forms - What is the best way to pass mailer arguments? - solved

Now you can add this code to config/bootstrap.php or to an addon to change your mail settings:

<?php
$app->on('forms.submit.before', function($form, &$data, $frm, &$options) {
    
    // mail subject
    $options['subject'] = 'custom special mail subject';
    
    // add reply_to
    $options['reply_to'] = trim($data['mail']);
    
    // cc and bcc
    $options['cc'] = ['mail1@example.com', 'mail2@example.com'];
    $options['bcc'] = ['mail1@example.com', 'mail2@example.com'];
    
});

Have a look at lib/Mailer and Forms/bootstrap.php to see more possible options.

Or try

I added a simple templating system for mail subjects and I’ll add more options for CC, BCC etc. soon.

2 Likes