Download the PHP package mouf/utils.mailer.mail-interface without Composer
On this page you can find all versions of the php package mouf/utils.mailer.mail-interface. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mouf/utils.mailer.mail-interface
More information about mouf/utils.mailer.mail-interface
Files in mouf/utils.mailer.mail-interface
Package utils.mailer.mail-interface
Short Description This package contains interfaces and classes describing mails. It also contains the MailerService interface that should be implemented by any service that can send mails. You should use a package implementing this interface (like the SmtpMailer package.
License MIT
Homepage https://github.com/thecodingmachine/utils.mailer.mail-interface
Informations about the package utils.mailer.mail-interface
Mouf Mail system
The Mouf framework is only an IOC framework. As such, it does not provide any means for managing any kind of cache. Hopefully, the Mouf team provides also a range of packages to manage sending mails.
The mail architecture
In Mouf, emails are sent using MailServices.
Mouf provides 4 implementations of mail services. You can provide your own if you want.
By default, Mouf provides these 3 implementations:
- SwiftMailService: a mail service that uses a SMTP server to send mails (this is a wrapper using the Swift mail library).
- SmtpMailService: a mail service that uses a SMTP server to send mails (this is a wrapper using the Zend_Mail library).
- DBMailService: a mail service that does not send any mails. Instead, it writes the mail in a MySQL database. It can forward the mail later to another mail service that will actually send the mail. This mail server is available in the package utils/mailer/db-mail-service.
Each mail service must extend the MailServiceInterface
interface that is part of the
package utils/mailer/mail-interface.
The mail service interface
Each class implementing the MailServiceInterface
provides one simple method to send mails:
The mail passed in parameter must implement the MailInterface
interface. Hopefully, Mouf provides a Mail
class
that does just that!
For instance, to send a mail, you just need to write:
The code above assumes that you configured an instance in Mouf called "smtpMailService".
The MailInterface
interface supports:
- Text/Html mails (
setBodyText
andsetBodyHtml
methods) - Multiple recipients (
addToRecipient
method) - Multiple Cc recipients (
addCcRecipient
method) - Multiple Bcc recipients (
addBccRecipient
method) - File attachments (
addAttachment
method)
Mail addresses are passed as a MailAddress
object, that contains 2 strings: the mail address and the alias.
Automatic text body generation
When sending mails, it is a good practice to send 2 bodies: one in plain text and one in HTML. Forget the plain text and your mail could be flagged as spam. However, most of the time, your users will look at the mail in HTML. Mail clients that can only read plain text are really rare those days.
The Mail
class can help you here. Indeed, it will automatically generate the plain text version of your mail
from the HTML, by stripping all tags.
If you want to explicitly disable the plain text generation you can call this method: