Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Field Variables to subject line #262

Closed
CreateSean opened this issue Apr 24, 2024 · 1 comment
Closed

Add Field Variables to subject line #262

CreateSean opened this issue Apr 24, 2024 · 1 comment
Labels

Comments

@CreateSean
Copy link

CreateSean commented Apr 24, 2024

Description

In the contact form plugin settings I'd like to be able to assign field variables to the subject text along the lines of this

New message from { message.fromName ?? 'No Name' } Company Website name contact form

I tried the above but it just outputs the text and not the value of the form field.

Steps to reproduce

Additional info

  • Craft version: 5.0.0
  • PHP version: 8.2.17
  • Database driver & version:
  • Plugins & versions: contact form 3.1.0
@CreateSean CreateSean added the bug label Apr 24, 2024
@i-just
Copy link
Contributor

i-just commented May 2, 2024

Hi, thanks for reaching out!

At the moment, that’s not possible via the plugin’s settings. The “Subject Text” will be prepended to the email’s Subject to flag that it comes from the Contact Form. So, if you have your “Subject Text” set to “New message from My Website” and the person filling out the form sets the subject to “About Something”, the subject will be: “New message from My Website - About Something”.

You can, however, manipulate the subject via Mailer::EVENT_BEFORE_SEND event (from a module or a plugin):

Event::on(Mailer::class, Mailer::EVENT_BEFORE_SEND, function(SendEvent $e) {
    $subject = $e->submission->subject;
    $settings = \craft\contactform\Plugin::getInstance()->getSettings();
    $e->message->setSubject("{$settings->prependSubject} - $subject - additional message");
});

I hope this helps!

@i-just i-just closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants