Tutorial: Adding Customer Name to OpenCart Registration Email

Whenever a new customer registers on one of our OpenCart stores, the customer and the site administrator are sent an OpenCart registration email that looks like this:

Welcome and thank you for registering at 10 Cent Books!

Your account has now been created and you can log in by using your email address and password byvisiting our website or at the following URL:
<a href="http://www.10centbooks.com/index.php?route=account/login&amp;sid=99999999999999999999999999999999">https://www.10centbooks.com/index.php?route=account/login&amp;sid=99999999999999999999999999999999</a>

Upon logging in, you will be able to access other services including reviewing past orders, printing invoices and editing your account information.

Thanks,
10 Cent Books

While it’s nice to know that someone has registered on our site, it would be much nicer to know who registered on the site. I wanted to see an email that looked more like this:

Bret Williams:
Welcome and thank you for registering at 10 Cent Books!

Your account has now been created and you can log in by using your email address and password by visiting our website or at the following URL:
<a href="http://www.10centbooks.com/index.php?route=account/login&amp;sid=99999999999999999999999999999999">https://www.10centbooks.com/index.php?route=account/login&amp;sid=99999999999999999999999999999999</a>

Upon logging in, you will be able to access other services including reviewing past orders, printing invoices and editing your account information.

Thanks,
10 Cent Books

The fix is quite simple once you know where to look among the OpenCart files:

  1. In your OpenCart file hierarchy (and this applies to OpenCart, v1.5; I have not confirmed earlier versions), find /catalog/model/account/customer.php.
  2. Duplicate this file for safety and download the file to your computer to edit. I use Coda for editing OpenCart installations. By control-clicking on the file name, you can choose Duplicate… and have a copy made of the original, either on the server or – better yet – in your local copy of your OpenCart installation.
  3. Open customer.php and find line 22. Add a “.” before “=” so the line now looks like this:
    $message .= sprintf($this->language->get('text_welcome'), $this->config->get('config_name')) . "nn";
  4. Before this line, add this:
    $message = $this->request->post['firstname'] . " " . $this->request->post['lastname'] . ":nn";
  5. Save and upload customer.php to your server.

And that’s it. What you’ve done is add the new customer’s first and last name as they entered it into the registration form.

If you want to change any of the language of the email, edit the language file /catalog/language/english/mail/customer.php. It’s short and straightforward enough that you’ll figure out how to edit this. Just a couple of notes, though:

  • “%s” refers to the Store Name.
  • If you want to force a line break, use “n” (backslash-n).

Have fun.

9 Responses to "Tutorial: Adding Customer Name to OpenCart Registration Email"
  1. Thank you so much for this tutorial! I looked around on the opencart forum but I couldn’t figure out how to add this to the registration email. I appreciate how easy it was. Just one word of warning to your readers. If you copy and paste the code make sure you retype the quotation marks. For some reason copying directly caused it to break whereas replacing the quotes fixed it. Thanks again!

  2. I followed the steps and even verified the missing quotations but my site fails when opening the registration page. Here is my changed code:

    $message = $this->request->post[‘firstname’] . ” ” . $this->request->post[‘lastname’] . “:nn”;

    $message .= sprintf($this->language->get(‘text_welcome’), $this->config->get(‘config_name’)) . “nn”;

    Any Ideas?

  3. Please disregard. I didn’t realize I needed to “re-type” the quotation marks if they already existed. Retyped them and it works just fine now.

    • Glad you got it working. I’m going to be installing a code update on this site so you can copy/paste code without having to re-do the quotations (it’s on a very long to-do list).

  4. This is working fine for me in opencart 1.5.2.1

    $message = “Hello, “.$data[‘firstname’].” “.$data[‘lastname’]. “nn” ;
    $message .= sprintf($this->language->get(‘text_welcome’), $this->config->get(‘config_name’)) . “nn”;

  5. Good day,

    Thank you for the tutorial. I will like to request for the VQMOD version.

    Also, i wanted to make mine look like this

    Dear “firstname” “Lastname”

Leave a Reply