Tedd Persson
Tedd Persson

Reputation: 37

Change subject on email sent through contact form in Prestashop

I have a problem, I want to change the subject on the email that we are getting when a customer writes to us through the contact form on a webpage.

I found the line where i change it:

if (!Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form').' [no_sync]', $var_list, $contact->email, $contact->name, null, null,

I want to change it to

Mail::l('Message from contact form - customers email')

Anyone know what I need to write there?

I tried like this but it returns 0 in subject: Mail::l('Message from contact form' - $contact->email),

Upvotes: 0

Views: 1577

Answers (2)

ButcherFromHell
ButcherFromHell

Reputation: 165

or you can make a simple module for that and use hook: hookActionEmailSendBefore

In module file use function something like this:

public function hookActionEmailSendBefore($params)
{
 if ($params['template'] == 'contact'  )
        {
            $emailClient= (string)$params['templateVars']['{email}'];
            
            $params['subject'] = $params['subject']." - ".$emailClient;
        }

}

I believe that contact is the name of template used for that and $params['templateVars']['{email}'] would be the email of client.

In $params['subject'] - you can modify the mail subject as you wish.

Hope that helps

Upvotes: 0

shagshag
shagshag

Reputation: 471

sprintf(Mail::l('Message from contact form - %s'), $contact->email)

your line will be

if (!Mail::Send($this->context->language->id, 'contact', sprintf(Mail::l('Message from contact form - %s'), $contact->email).' [no_sync]', $var_list, $contact->email, $contact->name, null, null,

Some details :

Mail::l() translates a text in current language, it should be a static text so Mail::l('Message from contact form' . $contact->email) is not a good solution.

Mail::l('Message from contact form' - $contact->email) can't work, PHP do the operation 'Message from contact form' - $contact->email before translate so translate 0

Mail::l('Message from contact form - ') . $contact->email works but is not a good practice, maybe in an other language the email is not placed at the end. Moreover PrestaShop sucks for translation of text ending by space.

sprintf(Mail::l('Message from contact form - %s'), $contact->email) uses a static text 'Message from contact form - %s' and sprintf replaces %s with customer's email. On an other language, %s can be placed where it should without code modification.

Upvotes: 1

Related Questions