0

テストメールを送信できないため、cakephp でメールをデバッグしようとしています。ただし、私が行うすべてのことは、デバッグであっても、空白の Web ページだけを提供します。私はすでにデバッグモードを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; ?> 
4

2 に答える 2

0

アクセス可能なSMTPサーバーを必要とする以外に、このステートメントを関数の外に置くこともできません...

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

また、このコマンドを使用すると、メールがセッション変数に保存されるだけで、送信されないこと注意してください。

于 2012-07-06T01:40:04.750 に答える
0

このアプリケーションをローカルで実行している場合、動作するようにメール サーバーをセットアップする必要があると思います。それ以外の場合は、任意のプロバイダーで smtp メール オプションを使用できます。そのためには、メール設定を構成する必要があります。

あなた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');
于 2012-05-03T03:14:20.640 に答える