mouf / utils.mailer.smtp-mail-service
此软件包包含一个使用SMTP服务器发送邮件的邮件发送器。该软件包是围绕Zend框架中的Zend_Mail类的一个包装。
v2.0.0
2014-03-06 11:08 UTC
Requires
- php: >=5.3.0
- mouf/utils.common.mouf-helpers: ~2.0
- mouf/utils.log.errorlog_logger: ~2.0
- mouf/utils.mailer.mail-interface: ~2.0
- zendframework/zend-eventmanager: ~2.1@stable
- zendframework/zend-mail: ~2.1@stable
- zendframework/zend-servicemanager: ~2.1@stable
- zendframework/zend-validator: ~2.1@stable
README
使用SmtpMailService
通过SMTP邮件服务器发送邮件。
SmtpMailService
设计得非常易于使用。在幕后,SmtpMailService
使用更复杂(但更强大)的ZendFramework 2邮件服务。
安装
此软件包是Mouf PHP框架的一部分。因此,它附带了一个图形化的安装程序。
您可以根据需要配置设置以连接到您的SMTP服务器。
有一个必填参数:host,它是服务器地址。
默认情况下,在Linux系统上,您很可能会使用本地邮件服务器(host=127.0.0.1)。您将在您的机器上安装“sendmail”或“postfix”服务器。如果您在Windows机器上开发,您很可能没有在您的机器上安装SMTP服务器。因此,您将必须使用远程服务器。要访问远程服务器,您可能需要使用用户名/密码等...
当此软件包安装时,它将创建一个默认的“smtpMailService”并在此实例中放置您提供的所有参数。
注意:没有任何东西阻止您创建多个具有不同参数的SmtpMailService类实例(在罕见的情况下,您的应用程序需要连接到多个SMTP服务器)。安装后,您会发现许多常量已添加到您的config.php
文件中。当在其他服务器上部署时,您当然可以更改这些常量以适应服务器的设置。
提示:使用您的Gmail帐户发送邮件
在开发环境中,使用您的Gmail帐户可能很有用。以下是设置
- host => 'smtp.gmail.com'
- ssl => 'tls'
- port => 587
- auth => 'login'
- username => 您的Gmail邮件地址
- password => 您的密码
示例使用
以下是您可以使用它来发送邮件的示例代码。
use Mouf\Utils\Mailer\Mail; use Mouf\Utils\Mailer\SmtpMailService; // First, let's create the mail object $mail = new Mail(); $mail->setTitle("My mail"); $mail->setBodyText("This is my mail!"); $mail->setBodyHtml("This is my <b>mail</b>!"); $mail->setFrom(new MailAddress("my@server.com", "Server")); $mail->addToRecipient(new MailAddress("david@email.com", "David")); // Let's get the instance of the service $mailService = Mouf::getSmtpMailService(); // Finally, we send the mail $mailService->send($mail);
要了解更多有关如何发送邮件的信息,请参阅Mouf邮件架构简介。