unarealidad/canarium-libraries-goalio-mail-service

使用配置中定义的 Google 账户发送电子邮件

dev-master 2016-12-23 10:18 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:36:32 UTC


README

使用配置中定义的 Google 账户发送电子邮件。

配置

在应用程序实例的 config/autoload/ 目录下创建一个文件 goaliomailservice.local.php

将以下内容粘贴到文件中

$google_username = '';
$google_password = '';

/**
 * You do not need to edit below this line
 */
return array(
    'goaliomailservice' => array(
        'transport_class' => 'Zend\Mail\Transport\Smtp',

        'options_class' => 'Zend\Mail\Transport\SmtpOptions',

        'options' => array(
            'host' => 'smtp.gmail.com',
            'connection_class' => 'login',
            'connection_config' => array(
                'ssl' => 'tls',
                'username' => $google_username,
                'password' => $google_password
            ),
            'port' => 587
        )
    )
);

使用您的 Google 账户凭证添加 $google_username$google_password 的值。请注意,这是一个本地文件,不会提交到仓库。

这就是在 canarium 中发送电子邮件所需的所有内容。

发送电子邮件

一旦初始化,服务 goaliomailservice_message 将可通过服务管理器检索。示例

$mailService = $this->getServiceLocator()->get('goaliomailservice_message');

现在发送电子邮件

  $message = $mailService->createHtmlMessage(
      $$from_email,
      $to_email,
      $subject,
      'index/email',
      $params
  );

  $mailService->send($message);

可用方法

createHtmlMessage

返回一个准备发送的 HTML 消息

public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values = array()):MailMessage;

createTextMessage

返回一个准备发送的文本消息

public function createTextMessage($from, $to, $subject, $nameOrModel, $values = array()):MailMessage;

send

发送邮件消息

public function send(MailMessage $message)