Page 1 of 1

[MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Sun Jun 06, 2010 2:34 pm
by trait
Dear All,
At the Back office, Sales -> Mail function, we can only send the mails with same Subject, and also same message.

So, I want to use some filed such as customer's name, customer's email..

And when I write the mail Subject, I can use {NAME} instead of customer's name.., so the message..

So, let show how I get start.

Modify: admin\controller\sale\contact.php
find

Code: Select all

$emails[$result['customer_id']] = $result['email'];
And then change it to

Code: Select all

$emails[] = array(
                                'name'           => $result['name'],
                                'email'          => $result['email']
                            );
Also find:

Code: Select all

$emails[] = $customer_info['email'];
and change to:

Code: Select all

$emails[] = array(
                            'name'           => $customer_info['name'],
                            'email'          => $customer_info['email']
                        );
Find :

Code: Select all

if ($emails) {
				$message  = '<html dir="ltr" lang="en">' . "\n";
				$message .= '<head>' . "\n";
				$message .= '<title>' . $this->request->post['subject'] . '</title>' . "\n";
				$message .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
				$message .= '</head>' . "\n";
				$message .= '<body>' . html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8') . '</body>' . "\n";
				$message .= '</html>' . "\n";
then change to:

Code: Select all

if ($emails) {
                $MailTitle = $this->request->post['subject'];
				$message  = '<html dir="ltr" lang="en">' . "\n";
				$message .= '<head>' . "\n";
				$message .= '<title>{TITLE}</title>' . "\n";
				$message .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
				$message .= '</head>' . "\n";
				$message .= '<body>'.html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8').'</body>' . "\n";
				$message .= '</html>' . "\n";

and last we need to change the sendmail function;
so find:

Code: Select all

				foreach ($emails as $email) {
					$mail = new Mail();	
					$mail->protocol = $this->config->get('config_mail_protocol');
					$mail->hostname = $this->config->get('config_smtp_host');
					$mail->username = $this->config->get('config_smtp_username');
					$mail->password = $this->config->get('config_smtp_password');
					$mail->port = $this->config->get('config_smtp_port');
					$mail->timeout = $this->config->get('config_smtp_timeout');				
					$mail->setTo($email);
					$mail->setFrom($this->config->get('config_email'));
					$mail->setSender($store_name);
					$mail->setSubject($this->request->post['subject']);					
					
					foreach ($attachments as $attachment) {
						$mail->addAttachment($attachment['path'], $attachment['filename']);
					}
					
					$mail->setHtml($message);
					$mail->send();
				}
And change to;

Code: Select all

				foreach ($emails as $email) {
                    $TmpTitle = $MailTitle;
                    $TmpBody = $message;
                    $TmpTitle = str_replace("{NAME}",$email["name"],$TmpTitle);
                    $TmpTitle = str_replace("{EMAIL}",$email["email"],$TmpTitle);
                    $TmpBody = str_replace("{NAME}",$email["name"],$TmpBody);
                    $TmpBody = str_replace("{EMAIL}",$email["email"],$TmpBody);
                    $TmpBody = str_replace("{TITLE}",$TmpTitle,$TmpBody);
					$mail = new Mail();	
					$mail->protocol = $this->config->get('config_mail_protocol');
					$mail->hostname = $this->config->get('config_smtp_host');
					$mail->username = $this->config->get('config_smtp_username');
					$mail->password = $this->config->get('config_smtp_password');
					$mail->port = $this->config->get('config_smtp_port');
					$mail->timeout = $this->config->get('config_smtp_timeout');				
					$mail->setTo($email['email']);
					$mail->setFrom($this->config->get('config_email'));
					$mail->setSender($store_name);
					$mail->setSubject($TmpTitle);					
					
					foreach ($attachments as $attachment) {
						$mail->addAttachment($attachment['path'], $attachment['filename']);
					}
					
					$mail->setHtml($TmpBody);
					$mail->send();
				}
			}
ok, it's done.

And I uploaded the new contact.php file.

I tested, It work fine:)

Good luck.
Ady.

Re: [MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Mon Jan 03, 2011 4:12 am
by silanli_53
How do we apply this method in order to contract..?

Re: [MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Wed Jan 05, 2011 3:58 pm
by kingdonk
i uploaded the file you attached to the post and it seems to break the mail page by not showing categories/products for customer selection, do sent search for customer and also do sent send any mail.

Im using the latest opencart release with no mods.

Re: [MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Tue Jan 11, 2011 2:45 pm
by philbydevil
I believe that I have fixed this to work with v1.4.9.3.

See attached file: admin/controller/sale/contact.php (rename txt extension of attached file to php).

It seems to work fine for me, but I don't know php so if one of the forum guru's would like to check it that would be great.

I mainly just changed the instances of 'name' to 'firstname' in the code that trait uploaded. I also merged his file with the new 1.4.9.3 file.

Hopefully it will work for others too.

Example:

Hello {NAME},

Your registered email address is: {EMAIL}.

Thanks for shopping with us.


{NAME} = first name only.

BACK UP FIRST!

*REMOVED FILE - it didn't work corectly.

Re: [MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Tue Jan 11, 2011 4:47 pm
by philbydevil
There is a problem with the mod (ie. file above) - it only sends to one email address (the first on the list), even if multiple are selected. Will have to look into this.

Re: [MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Fri Jan 14, 2011 8:51 am
by philbydevil
FIXED:

Many thanks to afwollis who has modified the coding to make this modification work.

See this thread: http://forum.opencart.com/viewtopic.php?f=20&t=25282

Re: [MOD] Use {NAME}, {EMAIL} in Sales => Mail

Posted: Wed Mar 02, 2011 9:07 pm
by scanreg
Will email tags and templates be part of OC 1.5.x?

This is the first I've seen this hack and it would be great in the core especially if you could create different email templates for different purposes.

I saw the vqmod:

http://forum.opencart.com/viewtopic.php?f=121&t=26380

Thanks