Post by trait » Sun Jun 06, 2010 2:34 pm

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.
Last edited by i2Paq on Mon Jun 07, 2010 12:57 am, edited 1 time in total.
Reason: Title adjusted + Topic moved

TRAIT-TECH.COM Wholesale electronics with factory price, dropshipper from China


User avatar
New member

Posts

Joined
Sat Apr 03, 2010 10:38 am


Post by silanli_53 » Mon Jan 03, 2011 4:12 am

How do we apply this method in order to contract..?

Cafe Koltuk Çeşitleri

Laptop Sırt Çantası


User avatar
New member

Posts

Joined
Fri Feb 19, 2010 8:54 am


Post by kingdonk » Wed Jan 05, 2011 3:58 pm

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.

Newbie

Posts

Joined
Wed Dec 22, 2010 6:03 pm

Post by philbydevil » Tue Jan 11, 2011 2:45 pm

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.
Last edited by philbydevil on Fri Jan 14, 2011 11:57 am, edited 1 time in total.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by philbydevil » Tue Jan 11, 2011 4:47 pm

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.

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by philbydevil » Fri Jan 14, 2011 8:51 am

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

I heart cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1


User avatar
Active Member

Posts

Joined
Fri Dec 03, 2010 5:20 am

Post by scanreg » Wed Mar 02, 2011 9:07 pm

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

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am
Who is online

Users browsing this forum: No registered users and 3 guests