Jump to content

Email notification - how to code?


grafis

Recommended Posts

The clue would be that the PHP code file that processes the data that the form submitted would then call the Mailer class, use various methods to setup the parts of an email, then use the send() method to get the email out the door.

That's just the clue.

I'll have a better explanation later.

Link to comment
Share on other sites

I'm working on adding the ability to have admin create more types of emails ("Welcome, thanks for registering", etc.).

But let's start by looking at /classes/order.class.php, at around line 282.

$admin_mailer = Mailer::getInstance();

This gives us a thing that we will use to do the mailing. The Mailer thing (an object) has properties (characteristics) and functions (actually called methods, that do actions).

if (($content = $admin_mailer->loadContent('admin.order_received')) !== false) {

The Mailer object knows how to fetch email content from the database. That content is actually a template used by Smarty and Smarty populates the {$placeholders} with data assembled in code from form submissions or other database calls. In the case we are looking at, that happened in lines 213-280. For this case, the email content being used is the message Order Received and is intended for the admins.

Because this is a Smarty template, we use the Smarty object's assign() method to populate the template. Then we use the Mailer's method sendMail(who, what) to send the email on its way.

To summarize:

Assign to a variable a Mailer object.

Determine what email content (which is a template) to send and give it to loadContent().

Use Smarty to populate the email content.

Use sendmail() to send it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...