Send e-mails using email queue
ImpressPages CMS has an email queue which carry all emails sent via ImpressPages CMS. It is good to use this queue in your plugin. Then you don't need to worry about correct headers, how to add file attachment or emails limit on shared server. Email queue will handle all of that for you and store copy of email in log (Administrator -> Email queue).
This is how you should send email on ImpressPages CMS:
<?php $emailQueue = new \Modules\administrator\email_queue\Module(); $emailQueue->addEmail($from, $fromName, $to, $toName, $subject, $content, $immediate, $html, $files = null); $emailQueue->send(); ?>
- $from - sender email
- $fromName - sender name
- $to - recipient email
- $toName - recipient name
- $content - email content. HTML or plane text.
- $immediate - true if email should be sent immediately
- $html - true if $content is HTML
- $files - array of paths to files to be attached. This could be temporary directory. Script will cache the file in the database.
Use email template
ImpressPages CMS has default email layout which contains greeting and signature below the email. Here is an example how to use it:
<?php
global $parametersMod;
$content = '<p>Text needed to be send.</p>'
$websiteName = $parametersMod->getValue('standard', 'configuration', 'main_parameters', 'name');
$websiteEmail = $parametersMod->getValue('standard', 'configuration', 'main_parameters', 'email');
$emailData = array(
'content' => $content,
'name' => $websiteName,
'email' => $websiteEmail
);
$content = \Ip\View::create(BASE_DIR.MODULE_DIR.'standard/configuration/view/email.php', $emailData)->render();
//put this $content variable as $content to above described addEmail function
Comments (4)
Kieran Cook
This is great. Thank you... but if I want emails from my contact page page to be sent to my email address, how do I achieve this?
Kieran Cook
additionally, how do I clear emails from the email queue?
Mangirdas
Open administration panel "Configuration" tab then navigate to "Main parameters" and change "Site e-mail" value to your email. In the future contact form widget will have separate config where to send data.
Mangirdas
You can clear emails by removing records from the database. But old records will be removed automatically. You shouldn't care about them.
Write a comment
You must be logged in to comment.