【问题标题】:Send smtp email with dynamic smtp options cakephp发送带有动态 smtp 选项 cakephp 的 smtp 电子邮件
【发布时间】:2014-12-18 21:01:47
【问题描述】:

我可以从 email.php 文件发送电子邮件配置 smtp 选项,它工作正常。但我想发送电子邮件,其中 smtp 选项,如主机、端口、用户名和密码是从数据库中获取的。

我尝试使用它,但不起作用,只是给出错误No connection could be made because the target machine actively refused it。 smtp 选项是正确的。

App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('smtp');

$Email->smtpOptions = array(
    'host' => $smtpAccount['host'],
    'port' => $smtpAccount['port'],
    'username' => $smtpAccount['username'],
    'password' => $smtpAccount['password'],
);

$Email->to($email);
$Email->template('sending')->emailFormat('both');
$Email->subject($subject);
$Email->viewVars (
    array(
        'content' => $content
    )
);

return $Email->send();

尝试将主机设置为$Email->host($smtpAccount['host']); 给出错误Call to undefined method CakeEmail::host()

谢谢

【问题讨论】:

    标签: email cakephp cakephp-2.0


    【解决方案1】:

    应该使用$Email->smtpOptions 而不是

    $Email->config(array(
        'host' => $smtpAccount['host'],
        'port' => $smtpAccount['port'],
        'username' => $smtpAccount['username'],
        'password' => $smtpAccount['password'],
    ));
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 2012-03-09
    • 2013-12-27
    • 2017-02-11
    • 1970-01-01
    相关资源
    最近更新 更多