【问题标题】:How do I setup Cakephp email?如何设置 Cakephp 电子邮件?
【发布时间】:2014-07-04 00:49:06
【问题描述】:

我想知道如何让这个 cakephp 电子邮件工作。我知识不多,但想知道我需要使用什么。我将为此使用我的网站电子邮件,例如 admin@website.com 但它能够通过 gmail 登录,因为它是这样设置的。谢谢。

<?php

class EmailConfig {

public $mail = array(
    'transport' => 'Mail',
    'from' => 'test@test.com',       
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
);

public $smtp = array(
    'transport' => 'Smtp',
    'from' => array('site@localhost' => 'My Site'),
    'host' => 'localhost',
    'port' => 25,
    'timeout' => 30,
    'username' => 'user',
    'password' => 'secret',
    'client' => null,
    'log' => false,
    //'charset' => 'utf-8',
    //'headerCharset' => 'utf-8',
);

public $gmail = array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'username' => 'test@test.com',
    'password' => 'myPass',
    'transport' => 'Smtp'
);

public $fast = array(
    'from' => 'you@localhost',
    'sender' => null,
    'to' => null,
    'cc' => null,
    'bcc' => null,
    'replyTo' => null,
    'readReceipt' => null,
    'returnPath' => null,
    'messageId' => true,
    'subject' => null,
    'message' => null,
    'headers' => null,
    'viewRender' => null,
    'template' => false,
    'layout' => false,
    'viewVars' => null,
    'attachments' => null,
    'emailFormat' => null,
    'transport' => 'Smtp',
    'host' => 'localhost',
    'port' => 25,
    'timeout' => 30,
    'username' => 'user',
    'password' => 'secret',
    'client' => null,
    'log' => true,
    //'charset' => 'utf-8',
    //'headerCharset' => 'utf-8',
);

}

【问题讨论】:

标签: php email cakephp


【解决方案1】:

这是一个适用于 Gmail / Google Apps 托管电子邮件的示例配置。您显然需要使用自己的电子邮件地址和密码填写。

class EmailConfig {
    public $default = array(
        'transport' => 'Smtp',
        'from' => array('example@domain.com' => 'Joe Bloggs'),
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'timeout' => 30,
        'username' => 'example@domain.com',
        'password' => 'YOUR_GMAIL_PASS_GOES_HERE'
    );
}

【讨论】:

    【解决方案2】:

    除非您希望连接到特定的 SMTP 服务器以发送电子邮件,否则您无需更改默认的 email.php。只需确保在通话中包含 from() 和 to() 即可。

    App::uses('CakeEmail', 'Network/Email');
    
    $Email = new CakeEmail();
    $Email->from(['noreply@host.com' => 'No Reply'])
        ->to('recipient@otherhost.com')
        ->subject('My subject')
        ->send('The body of the email');
    

    仅使用默认配置将使用您在 PHP 中设置的任何邮件功能。在 UNIX 机器上,机器通常会设置为中继邮件。在 Windows 机器上,您可能需要设置邮件中继,除非它是 SMTP 服务器。

    如果是你的开发环境和Windows,那么我建议设置smtp4dev。 smtp4dev 是一个非常方便的工具,它侦听端口 25,其行为类似于 SMTP 服务器。这将确保从您的开发环境中本地生成的任何电子邮件都不会发送到外部世界。

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 2014-07-07
      • 2011-02-22
      • 2015-08-22
      • 2011-01-10
      • 2016-03-10
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多