簡體   English   中英

調試電子郵件在cakephp中不起作用

[英]debugging email not working in cakephp

我試圖在cakephp中調試電子郵件,因為我無法發送測試郵件。 但是,我所做的一切都給我一個空白的網頁,甚至是調試。 我已經將調試模式設置為2。下面是我的代碼:

C:\\ xampp \\ htdocs \\ NewFolder \\ app \\ webroot \\ email \\ app \\ controllersmailer_controller.php

<?php  
class MailerController extends AppController { 

    var $name = 'Mailer'; 
    //Not using a model 
    var $uses = ''; 
    //The built in Cake Mailer 
    var $components = array('Email'); 

    $this->Email->delivery = 'debug';
    /** 
     * Send a text string as email body 
     */ 
    function sendSimpleMail() { 
        //$this->Email->to = 'yourlogin@localhost'; 
        $this->Email->to = 'csorila17@gmail.com'; 
        $this->Email->subject = 'Cake test simple email'; 
        $this->Email->replyTo = 'noreply@example.com'; 
        $this->Email->from = 'Cake Test Account <noreply@example.com>'; 
        //Set the body of the mail as we send it. 
        //Note: the text can be an array, each element will appear as a 
        //seperate line in the message body. 
        if ( $this->Email->send('Here is the body of the email') ) { 
            $this->Session->setFlash('Simple email sent'); 
        } else { 
            $this->Session->setFlash('Simple email not sent'); 
        } 
        //$this->redirect('/'); 
        $this->Email->delivery = 'debug';

    } 
} 
?> 

C:\\ xampp \\ htdocs \\ NewFolder \\ app \\ webroot \\ email \\ app \\ views \\ layouts \\ default.ctp

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

C:\\ xampp \\ htdocs \\ NewFolder \\ app \\ webroot \\ email \\ app \\ views \\ layouts \\ email \\ html \\ default.ctp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<body> 
<?php echo $content_for_layout; ?> 
<?php echo $this->Session->flash(); ?>
<?php echo $this->Session->flash('email'); ?>
</body> 
</html> 

C:\\ xampp \\ htdocs \\ NewFolder \\ app \\ webroot \\ email \\ app \\ views \\ layouts \\ email \\ text \\ default.ctp

<?php echo $content_for_layout; ?> 

如果您在本地運行此應用程序,我相信您需要設置一個郵件服務器才能工作,否則,您可以對任何提供程序使用smtp mail選項。 為此,您必須配置郵件設置。

在您的app\\config您可以創建一個文件email.php

<?php 
    class EmailConfig {

        public $default = array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'username' => 'your email address', //example@gmail.com
            'password' => 'password',
            'transport' => 'Smtp',
            'from' => array('From Email Address' => 'Name to be displayed in the Email'),
            'log' => true
        );

    }

之后,您可以在控制器中設置以下代碼來發送電子郵件。

$email = new CakeEmail();
$email->to('example@gmail.com');
$email->subject('Email testing Subject');       
$email->send('Email testing content');

除了需要可訪問的SMTP服務器外,您還不能將此語句放在函數之外...

$this->Email->delivery = 'debug';   // needs to be *inside* a function

另外請注意,當使用這個命令,它只會保存電子郵件到一個會話變量和發送。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM