The Pimcore Email Framework provides an easy way to send/create emails with Pimcore.
For this you have several components:
Pimcore provides a
Pimcore\Mail Class which extends the
If email settings are configured in your
config/config.yaml then on initializing
Pimcore\Mail object, these settings applied automatically
It is recommended to configure email settings in
pimcore: email: sender: name: 'Pimcore Demo' email: firstname.lastname@example.org return: name: '' email: ''
and debug email addresses should be configured in Admin Settings > System > Debug > Debug Email Addresses.
If the Debug Mode is enabled, all emails will be sent to the Debug Email recipients defined in Settings > System > Debug > Debug Email Addresses. Additionally the debug information (to whom the email would have been sent) is appended to the email and the Subject contains the prefix "Debug email:".
This is done by extending Symfony Mailer, with injected service
RedirectingPlugin, which calls beforeSendPerformed before mail is sent and sendPerformed immediately after email is sent.
Emails are sent via transport and
\Pimcore\Mailer requires transports:
main for sending emails and
pimcore_newsletter for sending newsletters(if newsletter specific settings are used), which needs to be configured in your config.yaml e.g.,
framework: mailer: transports: main: smtp://user:email@example.com:port pimcore_newsletter: smtp://user:firstname.lastname@example.org:port
Please refer to the Transport Setup for further details on how this can be set up.
Pimcore provides a
Document Email type where you can define the recipients ... (more information
here) and Twig variables.
To send a email you just create a
Email Document in the Pimcore Backend UI, define the subject,
recipients, add Dynamic Placeholders... and pass this document to the
Pimcore\Mail object. All
nasty stuff (creating valid URLs, embedding CSS, compile Less files, rendering the document..) is
automatically handled by the
Settings section of the
Email Document you can use
Full Username <email@example.com> or
Full Username (firstname.lastname@example.org) to set full username.
Lets assume that we have created a
Email Document in the Pimcore Backen UI (
which looks like this:
To send this document as email we just have to write the following code-snippet in our controller action:
//dynamic parameters $params = array('firstName' => 'Pim', 'lastName' => 'Core', 'product' => 73613); //sending the email $mail = new \Pimcore\Mail(); $mail->to('email@example.com'); $mail->setDocument('/email/myemaildocument'); $mail->setParams($params); $mail->send();
Sending a Plain Text Email:
$mail = new \Pimcore\Mail(); $mail->to('firstname.lastname@example.org'); $mail->text("This is just plain text"); $mail->send();
Sending a Rich Text (HTML) Email:
$mail = new \Pimcore\Mail(); $mail->to('email@example.com'); $mail->bcc("firstname.lastname@example.org"); $mail->html("<b>some</b> rich text"); $mail->send();