adcog-cpi / email-bundle
此包的最新版本(1.0.0)没有可用的许可证信息。
非常简单的邮件发送器
1.0.0
2016-03-14 12:28 UTC
Requires
- php: >=5.4
- symfony/swiftmailer-bundle: ~2.3
README
最低配置
只需添加您的发送者(实际上只需要一个)
eb_email:
senders:
-
name: John DOE
email: john.doe@gmail.com
emails: []
配置您的邮件
我们需要发送一个带有特定主题和正文的 contact
邮件。
eb_email:
# ...
emails:
contact:
subject: 'New contact !'
text_template: 'AppBundle:Email:_contact.txt.twig'
如果您想发送一个带有替代的 text/plain
和 text/html
的邮件,请使用 html_template
键
eb_email:
# ...
emails:
contact:
subject: 'New contact !'
text_template: 'AppBundle:Email:_contact.txt.twig'
html_template: 'AppBundle:Email:_contact.html.twig'
您可以在主题中使用 twig
语法
eb_email:
# ...
emails:
contact:
subject: 'New contact from {{contact.name}} !'
# ...
发送您的邮件
$this->get('eb_email')->send('contact', 'john.doe@gmail.com');
有 2 个收件人
$this->get('eb_email')->send('contact', [
'john.doe1@gmail.com',
'john.doe2@gmail.com',
]);
有实现 getUsername
方法的用户对象
$this->get('eb_email')->send('contact', $user);
有模板化的 message
变量
$this->get('eb_email')->send('contact', 'john.doe1@gmail.com', [
'message' => $message,
]);
带有 header
图片 <img src="{{ header }}"/>
$this->get('eb_email')->send('contact', 'john.doe1@gmail.com', [
'message' => $message,
], [
'header' => '/var/header.png',
]);
带有 PDF 附件
$this->get('eb_email')->send('contact', 'john.doe1@gmail.com', [
'message' => $message,
], [], [
'/var/attachment.pdf',
]);
为所有邮件配置全局、图片、附件和收件人
将 app_name
全局变量添加到所有邮件
eb_email:
# ...
globals:
app_name: BundleDemo
将 header
和 footer
图片添加到所有邮件(对 twig 布局很有用)
eb_email:
# ...
images:
header: /var/header.png
footer: /var/footer.png
将一些 PDF 添加到所有邮件
eb_email:
# ...
attachments:
- /var/terms.pdf
将收件人添加到所有邮件
eb_email:
# ...
recipients:
-
name: AppName
email: contact@appname.com
为单个邮件配置图片和附件
将 map
图片添加到 contact
邮件
eb_email:
# ...
emails:
contact:
# ...
images:
map: /var/map.png
向 contact
邮件添加一个 PDF
eb_email:
# ...
emails:
contact:
# ...
attachments:
- /var/satisfaction.pdf
向 contact
邮件添加一个默认收件人
eb_email:
# ...
emails:
contact:
# ...
recipients:
-
name: AppName
email: contact@appname.com
完整配置
# Default configuration for "EBEmailBundle"
eb_email:
senders: # Required
# Sender name
name: ~ # Required, Example: John Doe
# Sender email
email: ~ # Required, Example: john.doe@gmail.com
# Global to add in each template
globals: # Example: A parameter
# Prototype
name: ~
# Images to attach inline
images: # Example: /path/to/file
# Prototype
name: ~
# Files to attach
attachments: [] # Example: /path/to/file
recipients:
# Recipient name
name: ~ # Required, Example: John Doe
# Recipient email
email: ~ # Required, Example: john.doe@gmail.com
emails:
# Prototype
name:
# Text Template
text_template: ~ # Required, Example: AcmeDefautBundle::_text_email.html.twig
# HTML Template
html_template: null # Example: AcmeDefautBundle::_html_email.html.twig
# Email subject
subject: ~ # Required, Example: Welcome {{user.username}} to {{app_name}} !
# Global to add in this template
globals: # Example: A parameter
# Prototype
name: ~
# Images to attach inline
images: # Example: /path/to/file
# Prototype
name: ~
# Files to attach
attachments: [] # Example: /path/to/file
recipients:
# Recipient name
name: ~ # Required, Example: John Doe
# Recipient email
email: ~ # Required, Example: john.doe@gmail.com