Skip to main content
Version: 2.1

Email

Parthenon provides a robust system for sending emails which is easy to configure allowing you to start sending emails quickly. With our Email abstraction you'll be able to send emails and quickly switch from Email Service Providers with just a configuration.

Configuration

Config NameExampleRequiredDescription
from_nameParthenonfalseThe name of the email sender
from_address[email protected]falseThe address of the email address
providersendgridfalseThe mailing service to be used. Options are: null, sendgrid, mailgun, postmark,symfony
mailgunn/afalseThe mailgun options as defined in the Mailgun section below.
sendgridn/afalseThe sendgrid options as defined in the SendGrid section below.
postmarkn/afalseThe postmark options as defined in the Postmark section below.
send_via_queuefalsefalseWhen this flag is true then you can use the Symfony Messenger queue functionality to send the emails.

Example

parthenon:
notification:
enabled: true # by default is false.
email:
from_name: 'Parthenon'
from_address: '[email protected]'
provider: sendgrid
sendgrid:
api_key: 'a-cool-api-key-from-sendgrid'

Sending Emails

How sending emails work is that you create and message object from Parthenon\Notification\Message that is filled with the information for the email. This includes attachments, subject, and if there is a template name/id then that as well.

Parthenon\Notification\Email

This is the base class that forms the object representing the email that should be sent.

Methods

Method NameArgumentsReturn ValueDescription
setSubject?string $subjectselfSet the subject for the email
getSubjectn/a?stringReturns the subject for the email
getFromAddressn/a?stringReturns the email address that the email should be sent from
setFromAddress?string $fromAddressselfSets the email address that the email should be sent from
getFromNamen/a?stringReturns the name that the email should be sent from
setFromName?string $fromNameselfSets the name that the email should be sent from
getToAddressn/a?stringReturns the email address that the email should be sent to
setToAddress?string $toAddressselfSets the email address that the email should be sent to
getToNamen/a?stringReturns the name that the email should be sent to
setToName?string $toNameselfSets the name that the email should be sent to
getContentn/a?stringReturns the content for the email. This is only used if the template name is not set.
setContent?string $contentselfSets the content for the email. This is only used if the template name is not set.
getTemplateNamen/a?stringReturns the name of the template. With sendgrid this is the template id
setTemplateName?string $templateNameselfSets the name of the template. With sendgrid this is the template id
getTemplateVariablesn/aarrayReturns the variables for the template.
setTemplateVariablesarray $templateVariablesselfSets the variables for the template.
isTemplaten/aboolReturns if it's a template based email or not.
addAttachmentAttachment $attachmentselfAdds an attachement to be sent
getAttachmentsn/aarrayReturns the attachments to be sent with the email.

Parthenon\User\Notification\UserEmail

This is a helper class that creates an email for a user that automatically fills the name and address of the recipient of the email. It also adds the name of the user to the template variables under name.

Methods

Method NameArgumentsReturn ValueDescription
createFromUserUserInterface $userselfA static factory method.

Parthenon\Notification\TemplateEmail

TemplateEmail is a way of defining each email as it's own class.

<?php

namespace App\Email;

class WelcomeEmail extends \Parthenon\Notification\TemplateEmail {
public public function getTemplateName() {
return "TEMPLATE_ID";
}
}

Parthenon\User\Notification\UserTemplateEmail

UserTemplateEmail is a way of defining each email as it's own class.

<?php

namespace App\Email;

class WelcomeEmail extends \Parthenon\User\Notification\UserTemplateEmail {
public public function getTemplateName() {
return "TEMPLATE_ID";
}
}

Parthenon\Notification\Attachment

This is a class that represents the attachment that is being sent.

the template variables under name.

Methods

Method NameArgumentsReturn ValueDescription
__constructstring $name, mixed $contentselfThe constructor, the only way to set data for an Attachment is via the constructor
getNamen/astringReturns the filename of the attachment.
getContentn/astringReturns the content of the attachment file.

Example

$user = new User();
$sender = new Sender();

$userMessage = \Parthenon\User\Notification\UserMessage::createFromUser($user);

// SendGrid Template
// With SendGrid you only need to provide the template id as the subject comes from the template.
$userMessage->setTemplate('sendgrid-template-id');


// Mailgun template
// With Mailgun you need to set the subject
$userMessage->setTemplate('mailgun-template-name');
$userMessage->setSubject('The subject needs to be provided');

// Attachment
$attachment = new Parthenon\Notification\Attachment('filename.txt', 'file contents');
$userMessage->addAttachment($attachment);

$sender->send($userMessage);

SendGrid

To send emails via SendGrid you need to set the sender to SendGrid and provide an API Key.

{{% notice info %}} When you send an email using the SendGrid templates you don't need to set the subject. {{% /notice %}}

Config NameExampleRequiredDescription
api_keyasjdiofghdstrueThe API key for SendGrid
parthenon:
notification:
enabled: true # by default is false.
email:
from_name: 'Parthenon'
from_address: '[email protected]'
provider: sendgrid
sendgrid:
api_key: 'a-cool-api-key-from-sendgrid'

Postmark

To send emails via Postmark you need to set the sender to Postmark and provide an API Key.

Config NameExampleRequiredDescription
api_keyasjdiofghdstrueThe API key for Postmark
parthenon:
notification:
enabled: true # by default is false.
email:
from_name: 'Parthenon'
from_address: '[email protected]'
provider: postmark
postmark:
api_key: 'a-cool-api-key-from-postmark'

Mailgun

To send emails via Mailgun you need to set the sender to Mailgun and provide an API Key and domain.

Config NameExampleRequiredDescription
api_keyasjdiofghdstrueThe API key for Mailgun
api_urlhttps://api.eu.mailgun.netfalseThe domain for the Mailgun API. Normally only set to use EU servers instead of US ones.
domainexample.orgtrueThe domain you'll be sending emails from. The from email must match this domain.
parthenon:
notification:
enabled: true # by default is false.
email:
from_name: 'Parthenon'
from_address: '[email protected]'
provider: mailgun
mailgun:
api_key: 'a-cool-api-key-from-mailgun'
api_url: 'https://api.eu.mailgun.net'
domain: 'domain-that-you-send-emails-from.com'