https://github.com/oliver-schoendorn/mailer
A little zend-mail wrapper for easy composition of mime mails.
https://github.com/oliver-schoendorn/mailer
composer-library mailer mime-mails zend-framework zend-mail
Last synced: about 2 months ago
JSON representation
A little zend-mail wrapper for easy composition of mime mails.
- Host: GitHub
- URL: https://github.com/oliver-schoendorn/mailer
- Owner: oliver-schoendorn
- License: apache-2.0
- Created: 2017-08-01T13:23:31.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-22T10:58:14.000Z (about 7 years ago)
- Last Synced: 2025-01-15T13:09:31.419Z (4 months ago)
- Topics: composer-library, mailer, mime-mails, zend-framework, zend-mail
- Language: PHP
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oliver-schoendorn/mailer
This is a little zendframework/zend-mail wrapper that will automagically construct proper multipart mime mails.
Please feel free to submit pull requests.
## Installation
```bash
composer require oliver-schoendorn/mailer
```## Usage example
### Create new Mail object and initialize mail meta data
```php
setSubject('email subject')
->setSender('[email protected]', 'Foo Bar')
->setFrom('[email protected]', 'Foo Bar')
->setTo('[email protected]', 'Receipt name');
```### Add inline attachments
This is optional, but if you are using inline attachments, you have to keep track of the MailAttachment object, in order
to reference it in the html mail body.If an inline attachment is not being referenced, some mail clients will show the attachment or a preview below the mail,
which might break your carefully crafted mail layout.```php
setContent(fopen('path/to/file.jpg', 'r'))
->setMimeType('image/jpg');$mail->addInlineAttachment($inlineImage);
```### Add body parts
```php
addBodyPart((new MailBody())
->setMimeType(Mime::TYPE_TEXT)
->setContent('Plain text mail content'));$mail->addBodyPart((new MailBody())
->setMimeType(Mime::TYPE_HTML)
->setContent('Html mail content
'));
```### Add (non-inline) attachments
Usually, these only appear attachment in a context menu or similar, based on the mail client used.
```php
addAttachment((new MailAttachment('file.jpg'))
->setContent(fopen('path/to/file.jpg', 'r'))
->setMimeType('image/jpg'));
```### Sending the mail
To send an mail, you can either define the transport object directly using the Zend classes or you can use the built
in MailTransportFactory, which provides some type hinting.```php
createSmtpTransportWithLogin(
$config['mail']['user'],
$config['mail']['pass'],
$config['mail']['encryption'],
$config['mail']['name'],
$config['mail']['host'],
$config['mail']['port']
);$mail->send($mailTransport);
```## License
Copyright 2018 Oliver Schöndorn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.