jaimevalasek/jv-mail

为ZF2设计的通用邮件发送模块。

dev-master 2013-09-26 19:22 UTC

This package is not auto-updated.

Last update: 2024-09-24 05:59:06 UTC


README

创建者:Jaime Marcelo Valasek

使用此模块从您的网站发送电子邮件。

未来视频教程可以在网站或YouTube频道 http://www.zf2.com.br/tutoriais http://www.youtube.com/zf2tutoriais 上开发和发布

安装

将此模块下载到您的供应商文件夹中。

完成上述步骤后,打开文件config / application.config.php。并添加名为JVMail的模块。

使用JVMail

  • 将以下代码添加并配置到module.config.php文件中
  • 身份验证选项 'transportSsl' 和ssl与tls之间的连接类型
'JVMail' => array(
    'transport' => array(
        'smtpOptions' => array(
            'host' => 'smtp.domain.com',
            'port' => 587,
            'connection_class' => 'plain',
            'connection_config' => array(
                'username' => 'user@domain.com',
                'password' => 'password',
                'from' => 'anyemail@domain.com'
            ),
        ),
        'transportSsl' => array(
            'use_ssl' => false,
            'connection_type' => 'tls' // ssl, tls
        ),
    ),
    'options' => array(
        'type' => 'text/html',
        'html_encoding' => \Zend\Mime\Mime::ENCODING_8BIT,
        'message_encoding' => 'UTF8'
    )
),

如何使用

  • 您需要在发送电子邮件的模块中创建HTML模板,例如

application/view/mailtemplates/teste.phhtml

  • 您可以使用setData代码在视图模板中插入变量,例如发送电子邮件

$mail = new Mail($this->getServiceLocator()->get('servicemanager')); $mail->setData(array('nome' => 'Jaime Marcelo Valasek', 'email' => 'jaime.valasek@gmail.com'))

  • HTML模板
Teste de envio de email pelo Modulo JVMail.

Nome: <?php echo $this->nome?> <br>
Email: <?php echo $this->email?>
  • 实例化类mail并发送邮件的完整PHP代码。
use JVMail\Service\Mail;

$mail = new Mail($this->getServiceLocator()->get('servicemanager'));
$mail->setSubject('Teste de envio de email pelo modulo JVMail')
    ->setTo('recipientemail@domain.com')
    ->setData(array('nome' => 'Jaime Marcelo Valasek', 'email' => 'jaime.valasek@gmail.com'))
    ->setViewTemplate('teste')
    ->send();