Jump to content
thirty bees forum
  • 0

contact us form gives email not send error


Dolfijn

Question

Hello,

I'm puzzled why I can't get the contact-us form not working anymore. My email system is working fine with test messages and also messages are send correctly during the order process. But when anybody submits the contact-us form, there is an error message displayed after some 10 seconds or so (and the submitted info is stored in the backoffice).  I'm using TB 1.08 and I have migrated from PS 1.6.18 (half a year ago or so).

I already looked at the code in the ContactController.php and was able to figure out that it is the error message that is generated in this function:

 if (empty($contact->email)) {
                        Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $varList, $from, null, null, null, $fileAttachment);
                    } else {
                        if (!Mail::Send(
                            $this->context->language->id,
                            'contact',
                            Mail::l('Message from contact form').' [no_sync]',
                            $varList,
                            $contact->email,
                            $contact->name,
                            null,
                            null,
                            $fileAttachment,
                            null,
                            _PS_MAIL_DIR_,
                            false,
                            null,
                            null,
                            $from
                        ) || !Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $varList, $from, null, null, null, $fileAttachment, null, _PS_MAIL_DIR_, false, null, null, $contact->email)
                        ) {
                            $this->errors[] = Tools::displayError('An error occurred while sending the message 3.');
                        }

but I don't understand why this can happen. I also don not understand why I can't find only one .tpl file (contact-form.tpl, I would expect also a contact.tpl file). And what does this code do? Is it trying to send two mails (I'm not an php expert)?

I'm afraid that I'm missing something. Any help is apprectiated a lot!

Edit: I already figured out that there are indeed two templates for the emails. I'm afraid I have to debug the Mail::Send function to find the cause of this issue. But I'm still not sure what the code above is doing exactly..

 

Edited by Dolfijn
Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Final solution : it turns out that this bug (not getting the Shop ID from the current context) is already fixed in the Mail::Send function. Only available in bleeding edge. So I migrated to the latest greatest and it all works well.

Thanks for the pointers.

Link to comment
Share on other sites

  • 0
8 hours ago, Dolfijn said:

Hello,

I'm puzzled why I can't get the contact-us form not working anymore. My email system is working fine with test messages and also messages are send correctly during the order process. But when anybody submits the contact-us form, there is an error message displayed after some 10 seconds or so (and the submitted info is stored in the backoffice).  I'm using TB 1.08 and I have migrated from PS 1.6.18 (half a year ago or so).

I already looked at the code in the ContactController.php and was able to figure out that it is the error message that is generated in this function:

but I don't understand why this can happen. I also don not understand why I can't find only one .tpl file (contact-form.tpl, I would expect also a contact.tpl file). And what does this code do? Is it trying to send two mails (I'm not an php expert)?

I'm afraid that I'm missing something. Any help is apprectiated a lot!

Edit: I already figured out that there are indeed two templates for the emails. I'm afraid I have to debug the Mail::Send function to find the cause of this issue. But I'm still not sure what the code above is doing exactly..

 

Likely reason is missing email template for some language. The system is indeed trying to send 2 emails, one to admin and one to customer. It uses current customer selected language to find the email templates. It will need 4 email templates in order to send emails correctly:

/mails/<language>/contact.html
/mails/<language>/contact.txt
/mails/<language>/contact_form.html
/mails/<language>/contact_form.txt

If one of them doesn't exists for any of the language your customers can use, you'll experience this issue.

The obvious solution is to make sure these templates exists for all installed languages. 

And, also, I would suggest you upgrade to 1.1.0 or 1.1.x -- this functionality was redesigned and it now *survives* these situation by using fallback email templates (english version) if they exists. And it logs information about any missing email templates to Advanced Parameters > Logs, so you can easily figure out the issue and fix it.

  • Like 1
Link to comment
Share on other sites

  • 0

I have upgraded to 1.1 stable 🙂

Unfortunately, it did not resolve my problem (both mails are not send). I checked the new code and found out that it indeed restores to the default 'en' language versions of the templates. But I was already using them as I only run the shop in English. I also think that the email templates have moved? I'm using a customized theme (from PS 1.6.X) and I thought that the email templates were used from the theme directory. But anyway, I don't think I have an email template problem (also no mention of any problem in the error log). I also checked if both Mail::Send function fail and they both do. Maybe there is a problem in using the old PS 1.6.x theme? Because I'm using the old PS 'contact-form.tpl' file to render the contact-us page. If I use the TB version, the send button doesn't work any more (among other things). So I switched back to the old PS version..

So, I think I should have a look in the Mail::Send function itself? I already checked the input paramaters. They all look good.

P.S. The log shows some errors 3132 " CustomerThread deletion". Is that indicating something significant issue for this problem?

 

Edited by Dolfijn
Link to comment
Share on other sites

  • 0

Hi there. The problem of not sending the emails is solved (with the help of Datakick). TB was using a non existing email address. As far as I understand that was due to a misconfiguration but I'm not sure of that anymore. The reason for my hesitation is that although the emails are send correctly, the shop name and logo are of the wrong shop (yes, I'm using a multishop config). As far as I can understand this is the situation now:

There are two shops A and B. And A was using a non existing email address. And B the correct one. But if a user visits the domain of shop B and uses the contact-us page, the emails are (now) send using the shop name, logo and address of shop A (which is very confusing for a customer). The above email problem was therefore fixed by configuring shop A and B with the same email address (being that of shop B). That would explain that the 'right' email address is used and the wrong logo and shop name.

Can that be true?

I checked the multistore settings and I'm quite confidant that the settings of shop B are correct.

Edited by Dolfijn
Link to comment
Share on other sites

  • 0

The thing about multistore configuration is that there exists multiple layers of configuration. 

  • for specific shop
  • for shop group
  • for all shops

When some configuration key is not found for specific shop, it will fall-back to more generic settings. In your case, you have configuration on All Shops level set up the same as for your shop B, and (some) configuration key for specific shop A weren't set up correctly. So, thirtybees merged these settings, and resulting mix was not valid stmp configuration. 

The same probably happens with logo

  • Like 1
Link to comment
Share on other sites

  • 0

Still struggling with the multi store settings as they look ok to me. So I looked in the database. At least there it is obvious that the tables ps_shop and ps_shop_group and ps_shop_url are sound.

But ps_configuration doesn't look ok. A lot of names like PS_NAME, PS_SHOP_NAME, PS_SHOP_MAIL, PS_SHOP_EMAIL have either a group ID, shop ID of 1, 2 (shop B) or those values are null, null for shop A (I would expect 1, 1). Also not all names exist for both shops?

I can easily change the values of shop A to the correct group and shop ID. I can also add the missing names. Should I make does changes?

Second thing that I looks strange to me is that when the emails are composed, the shop context always returns a shopId of 0 (hence the default name and logo). But I would expect a shopId of either 1 or 2 again. When I force the ID to 1 or 2, I get the correct shop name and logo..

Edited by Dolfijn
Link to comment
Share on other sites

  • 0

The reported problem turned out to be slightly different then it appeared at first sight. It was a combination of an email address that didin't exist and and a bug in the ContactController which caused the code to ignore multishop settings. Easy to make wrong conclusions then.

The shop ID is never parsed to the function Mail::Send. So it uses the default value of null. And thus will never select the right logo or shop name in a multi shop environment.

I added a line of code to get the shop ID from the current context (this->context->shop->id) and parsed the value into the Mail::Send function (at three location as there are three possible execution flows). Et voilà, it now works correctly when using multiple shops. So, the emails send use the correct shopname and logo.

Changed code looks as follows (ContactController.php) :

$idShop = (int) $this->context->shop->id;

                    if (empty($contact->email)) {
                        Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $varList, $from, null, null, null, $fileAttachment, null, _PS_MAIL_DIR_, false, $idShop, null, null);
                    } else {
                        if (!Mail::Send(
                            $this->context->language->id,
                            'contact',
                            Mail::l('Message from contact form').' [no_sync]',
                            $varList,
                            $contact->email,
                            $contact->name,
                            null,
                            null,
                            $fileAttachment,
                            null,
                            _PS_MAIL_DIR_,
                            false,
                            $idShop,
                            null,
                            $from
                        ) || !Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $varList, $from, null, null, null, $fileAttachment, null, _PS_MAIL_DIR_, false, $idShop, null, $contact->email)
                        ) {
                            $this->errors[] = Tools::displayError('An error occurred while sending the message.');
                        }
                    }
                }

So I think this is a bug. But as always with the wonderful world of PS/TB, I'm never sure because I'm not deeply involved. But it works for me.

 

Edited by Dolfijn
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...