2012-05-03 8 views
0

テストメールを送信できないため、cakephpで自分の電子メールをデバッグしようとしています。しかし、私がやっていることは、まったく空白のWebページ、つまりデバッグしているだけです。cakephpでデバッグ電子メールが機能しない

C:私はすでに以下の私のコードがある2にデバッグモードを設定\ xamppの\:\ xamppの\ htdocsに\新規フォルダ\アプリ\ Webルート\アプリ\ 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 = '[email protected]'; 
     $this->Email->to = '[email protected]'; 
     $this->Email->subject = 'Cake test simple email'; 
     $this->Email->replyTo = '[email protected]'; 
     $this->Email->from = 'Cake Test Account <[email protected]>'; 
     //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メール\ htdocsに\新規フォルダ\アプリ\ Webrootの電子メール\アプリ\ビュー\レイアウト\ \ default.ctpに

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

C:\ xamppの\ htdocsに\新規フォルダ\アプリ\ Webルート\電子メール\アプリ\ビュー\レイアウト\メール\ 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に\新規フォルダ\アプリ\ Webrootの電子メール\アプリ\ビュー\レイアウト\電子メールの\テキスト\のdefault.ctpに

<?php echo $content_for_layout; ?> 

答えて

0

\、私はあなたが必要と考えていますメールサーバーを動作させるために設定する必要があります。そうしないと、プロバイダーのいずれかでsmtpメールオプションを使用できます。そのためには、メール設定を構成する必要があります。で

app\configあなたはセットアップが電子メールを送信するには、次のコードを使用することができ、あなたのコントローラで、この後にファイルemail.php

<?php 
    class EmailConfig { 

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

    } 

を作成することができます。アクセスSMTPサーバーを必要とする以外に他の

$email = new CakeEmail(); 
$email->to('[email protected]'); 
$email->subject('Email testing Subject');  
$email->send('Email testing content'); 
+0

gvLearner、この行は何をしますか?$ email = new CakeEmail(); – Charmie

+0

はcakephpの組み込み関数ですか? – Charmie

+0

とポート、それは常に465ですか? – Charmie

0

、あなたはまた、関数の外でこの文を配置することはできません...

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

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

関連する問題