【问题标题】:cakephp 2.0 Email Debug is not workingcakephp 2.0 电子邮件调试不起作用
【发布时间】:2012-11-26 06:34:31
【问题描述】:

我正在实现电子邮件功能,它也可以正常工作。现在我必须在本地调试所以做了一些更改,如下所示 在 app/config/email.php 我创建了这个

public $test = array(
        'from' => 'you@localhost',
        'transport' => 'Debug',
    );

现在在我的控制器中,我编写了以下代码

            $Email = new CakeEmail('test');

        $email->template('adddoctor', 'add');

        //$email->emailFormat('html');


        $email->from('sender@example.com');

        $email->to('recipient@example.com');//$data['User']['email_id'];

        $email->subject('Account Detail');


        $email->send();

发送邮件后,它会重定向到索引页面。所以在 index.ctp 文件中我写了

<?php echo $this->Session->flash('email'); ?>

我不想发送实际邮件,但我只想显示它。 那么任何人都可以告诉我对于电子邮件调试我还需要做哪些更改吗? 这里有些人给出了答案 CakeEmail debug

但不明白在哪里编写该代码?

【问题讨论】:

    标签: debugging email cakephp cakephp-2.0


    【解决方案1】:

    这是您将电子邮件保存到日志所需执行的操作,这与您尝试实施的其他问题的解决方案有关:

    app/Config/email.php

    public $test = array(
        'log' => true
    );
    

    你的控制者

    $Email = new CakeEmail('test');
    $email->template('adddoctor', 'add');
    $email->from('sender@example.com');
    $email->to('recipient@example.com');
    $email->subject('Account Detail');
    $email->send();
    

    如果您随后进入 app/tmp/logs/debug.log,您将看到您的电子邮件条目,其中包括标题和消息

    2012-11-27 14:37:47 Debug: 
    From: My Site <me@example.com>
    X-Mailer: CakePHP Email
    Date: Tue, 27 Nov 2012 14:37:47 +0000
    Message-ID: <50ad02b4b1fba42733cc02456a@example.com>
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    My message
    

    但是,在我看来,除非您想查看标题,否则这一切都毫无用处。首先,您实际上无法“看到”您的电子邮件的外观,其次,电子邮件将继续发送给收件人。

    如果您想查看电子邮件的实际布局/CSS 是什么样子,最好只给自己发送一些测试电子邮件。

    我不知道为什么 Cake 去掉了旧的电子邮件调试功能,因为它更有帮助。

    【讨论】:

      【解决方案2】:
      $Email = new CakeEmail('test');
      $email->template('adddoctor', 'add');
      

      您将对象创建为 $Email 并使用 $email 是错字吗?

      【讨论】:

        【解决方案3】:
        $response = $Email->send();
        
        $response['headers']; // headers as string
        $response['message']; // message body with attachments
        
        $this->Session->setFlash($response['headers'].$response['message']);
        

        确保您的布局文件中有以下内容。

        echo $this->Session->flash();
        

        【讨论】:

          猜你喜欢
          • 2011-05-18
          • 1970-01-01
          • 2012-03-09
          • 1970-01-01
          • 2014-08-05
          • 2012-01-04
          • 2014-03-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多