Jump to content

Custom Contact Form : Client Receiving Email But Not Me (Admin)


Recommended Posts

Hello everyone,

 

First, I'll describe what's my problem :

 

I created a new custom contact form (.tpl, .php, and controller files).

Everything's working fine EXCEPT that I don't receive any mail (GMAIL). But my client does receive the confirmation email !

 

In fact, I first modified the basic contact form deliver with prestashop (contact-form.tpl) and I'm not getting any trouble (form & mails are working fine).

So I went to create a new contact form based on what I did for the actual one in prestashop.

 

To resume :

 - Basic contact form modified is working fine.

 - New contact form created is working fine BUT I'm not receiving email (the client does).

 

Of course, nothing in my trash box or whatever.

 

Here's my code for my controller (actually maybe something wrong here?) :

if (empty($contact->email)) {
                        Mail::Send($this->context->language->id, 'pro_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')), $var_list, $from, null, null, null, $file_attachment);
                    } else {
                        if (!Mail::Send($this->context->language->id, 'pro', Mail::l('Message from contact form').' [no_sync]',
                            $var_list, $contact->email, $contact->name, null, null,
                                    $file_attachment, null,    _PS_MAIL_DIR_, false, null, null, $from) ||
                                !Mail::Send($this->context->language->id, 'pro_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')), $var_list, $from, null, null, null, $file_attachment, null, _PS_MAIL_DIR_, false, null, null, $contact->email)) {
                            $this->errors[] = Tools::displayError('An error occurred while sending the message.');
                        }
                    }

And in my log, there is only mail to the client : 

872595Capturedcran20151202150209.png

 

It's like in my code I'll never send email with model "pro", just "pro_form" to the client.

 

Thank you in advance,

Simon.

Link to comment
Share on other sites

Hell guys,

 

I found where my problem is but can't figure out why !!

 

Ok, so the problem is in my controller (called ProController.php), precisely in the send mail function.
There is a if condition which look if $contact->mail is empty or not; if it is, it only send a mail to the client.

 

And in this case, this condition return true (so the mail is empty, it can't find it!).

 

Here's my code (bug) : 


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

Here is my fixing/modified code :

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

So I deleted the condition and replace the $contact->mail with my mail and it's working !

Great, that's fine but it's an ugly fix.

 

HOW and WHY this $contact->mail is empty???

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...