【问题标题】:Sending different emails in cakephp在 cakephp 中发送不同的电子邮件
【发布时间】:2015-10-10 14:51:30
【问题描述】:

我需要发送两封不同的电子邮件,一封是给管理员,另一封是确认邮件,供用户确认我们已收到他的请求。我不知道如何在 cakephp 的同一操作中准确地将不同的电子邮件发送到不同的电子邮件地址。

代码:

控制器

    $Email = new CakeEmail('notifications');

    $result =           $Email->to(array('admin@example.com'))                  
                        ->subject(__("Request Notification))
                        ->send($message);


  if($result){

                $this->redirect('/pages/thankyou'); 
                $companymsg= "Dear,Thank you for you interest we will contact you soon."
                $Email = new CakeEmail('usernotifications');

                $Email->to(array($email))                   
                      ->subject(__(" Request"))
                      ->send($companymsg);


}

邮件配置

public $notifications = array(
        'transport' => 'Mail',
        'from' => array('notifications-noreply@example.com' => '(Notification)'),
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',
        'emailFormat' => 'html',
    );


    public $usernotifications = array(
    'transport' => 'Mail',
    'from' => array('no-reply@example.com' => 'My Project'),
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
    'emailFormat' => 'html',
);

【问题讨论】:

  • ->subject(__("Request Notification)) 中缺少双引号。这应该会引发致命错误,但您说的是它正在发送您的一封电子邮件。加上双引号并评论 $ this->redirect('/pages/thankyou'); 线并尝试。如果它仍然不起作用,请告诉我。
  • 仍然只发送一封电子邮件
  • 尝试设置 Configure::write('debug', 2);在你的控制器中,看看有什么错误。发送第二封电子邮件时似乎出现了一些错误。请让我知道错误。
  • 确保变量 $email 具有正确的电子邮件地址。

标签: php email cakephp cakephp-2.0


【解决方案1】:
Try:
$Email = new CakeEmail('notifications');
$result = $Email->to(array('admin@example.com'))                  
->subject(__("Request Notification))
->send($message);
$companymsg= "Dear,Thank you for you interest we will contact you soon."
$Email = new CakeEmail('usernotifications');
$Email->to(array($email))                   
->subject(__(" Request"))
->send($companymsg);
$this->redirect('/pages/thankyou');

【讨论】:

  • 不,它仍然只发送一封电子邮件
猜你喜欢
  • 2014-01-17
  • 2011-11-12
  • 2016-09-02
  • 1970-01-01
  • 2018-07-16
  • 2013-04-08
  • 2013-04-01
  • 2012-06-14
  • 1970-01-01
相关资源
最近更新 更多