2012-04-12 47 views
0

我有一个应该发送电子邮件的kohana框架的表单构建。如何调试不发送电子邮件的表单?

当我按下“发送”按钮,一切似乎工作正常......没有错误信息......但没有电子邮件出现!

如果我在firebug中看不到任何东西,我可以在哪里看?

的应用程序日志状态

"error: Missing i18n entry contact.captcha.valid for language en_US"

,但我不知道怎么去的problem..any帮助欢迎.. 你的底,

罗布

生病尝试找出哪个版本即时通讯使用.....应用程序是Ushahidi的最新版本(2.2.1)www.ushahidi.com

<?php defined('SYSPATH') OR die('No direct access allowed.'); 

/** *验证码库。 * * $编号:Captcha.php 3917 2009-01-21 03:06:22Z zombor $ * * @package验证码 * @author Kohana的团队 * @copyright(C)2007-2008 Kohana的团队 * @license http://kohanaphp.com/license.html */ 类Captcha_Core {

// Captcha singleton 
protected static $instance; 

// Style-dependent Captcha driver 
protected $driver; 

// Config values 
public static $config = array 
(
    'style'  => 'basic', 
    'width'  => 150, 
    'height'  => 50, 
    'complexity' => 4, 
    'background' => '', 
    'fontpath' => '', 
    'fonts'  => array(), 
    'promote' => FALSE, 
); 

/** 
* Singleton instance of Captcha. 
* 
* @return object 
*/ 
public static function instance() 
{ 
    // Create the instance if it does not exist 
    empty(self::$instance) and new Captcha; 

    return self::$instance; 
} 

/** 
* Constructs and returns a new Captcha object. 
* 
* @param string config group name 
* @return object 
*/ 
public static function factory($group = NULL) 
{ 
    return new Captcha($group); 
} 

/** 
* Constructs a new Captcha object. 
* 
* @throws Kohana_Exception 
* @param string config group name 
* @return void 
*/ 
public function __construct($group = NULL) 
{ 
    // Create a singleton instance once 
    empty(self::$instance) and self::$instance = $this; 

    // No config group name given 
    if (! is_string($group)) 
    { 
     $group = 'default'; 
    } 

    // Load and validate config group 
    if (! is_array($config = Kohana::config('captcha.'.$group))) 
     throw new Kohana_Exception('captcha.undefined_group', $group); 

    // All captcha config groups inherit default config group 
    if ($group !== 'default') 
    { 
     // Load and validate default config group 
     if (! is_array($default = Kohana::config('captcha.default'))) 
      throw new Kohana_Exception('captcha.undefined_group', 'default'); 

     // Merge config group with default config group 
     $config += $default; 
    } 

    // Assign config values to the object 
    foreach ($config as $key => $value) 
    { 
     if (array_key_exists($key, self::$config)) 
     { 
      self::$config[$key] = $value; 
     } 
    } 

    // Store the config group name as well, so the drivers can access it 
    self::$config['group'] = $group; 

    // If using a background image, check if it exists 
    if (! empty($config['background'])) 
    { 
     self::$config['background'] = str_replace('\\', '/', realpath($config['background'])); 

     if (! is_file(self::$config['background'])) 
      throw new Kohana_Exception('captcha.file_not_found', self::$config['background']); 
    } 

    // If using any fonts, check if they exist 
    if (! empty($config['fonts'])) 
    { 
     self::$config['fontpath'] = str_replace('\\', '/', realpath($config['fontpath'])).'/'; 

     foreach ($config['fonts'] as $font) 
     { 
      if (! is_file(self::$config['fontpath'].$font)) 
       throw new Kohana_Exception('captcha.file_not_found', self::$config['fontpath'].$font); 
     } 
    } 

    // Set driver name 
    $driver = 'Captcha_'.ucfirst($config['style']).'_Driver'; 

    // Load the driver 
    if (! Kohana::auto_load($driver)) 
     throw new Kohana_Exception('core.driver_not_found', $config['style'], get_class($this)); 

    // Initialize the driver 
    $this->driver = new $driver; 

    // Validate the driver 
    if (! ($this->driver instanceof Captcha_Driver)) 
     throw new Kohana_Exception('core.driver_implements', $config['style'], get_class($this), 'Captcha_Driver'); 

    Kohana::log('debug', 'Captcha Library initialized'); 
} 

/** 
* Validates a Captcha response and updates response counter. 
* 
* @param string captcha response 
* @return boolean 
*/ 
public static function valid($response) 
{ 
    // Maximum one count per page load 
    static $counted; 

    // User has been promoted, always TRUE and don't count anymore 
    if (self::instance()->promoted()) 
     return TRUE; 

    // Challenge result 
    $result = (bool) self::instance()->driver->valid($response); 

    // Increment response counter 
    if ($counted !== TRUE) 
    { 
     $counted = TRUE; 

     // Valid response 
     if ($result === TRUE) 
     { 
      self::instance()->valid_count(Session::instance()->get('captcha_valid_count') + 1); 
     } 
     // Invalid response 
     else 
     { 
      self::instance()->invalid_count(Session::instance()->get('captcha_invalid_count') + 1); 
     } 
    } 

    return $result; 
} 

/** 
* Gets or sets the number of valid Captcha responses for this session. 
* 
* @param integer new counter value 
* @param boolean trigger invalid counter (for internal use only) 
* @return integer counter value 
*/ 
public function valid_count($new_count = NULL, $invalid = FALSE) 
{ 
    // Pick the right session to use 
    $session = ($invalid === TRUE) ? 'captcha_invalid_count' : 'captcha_valid_count'; 

    // Update counter 
    if ($new_count !== NULL) 
    { 
     $new_count = (int) $new_count; 

     // Reset counter = delete session 
     if ($new_count < 1) 
     { 
      Session::instance()->delete($session); 
     } 
     // Set counter to new value 
     else 
     { 
      Session::instance()->set($session, (int) $new_count); 
     } 

     // Return new count 
     return (int) $new_count; 
    } 

    // Return current count 
    return (int) Session::instance()->get($session); 
} 

/** 
* Gets or sets the number of invalid Captcha responses for this session. 
* 
* @param integer new counter value 
* @return integer counter value 
*/ 
public function invalid_count($new_count = NULL) 
{ 
    return $this->valid_count($new_count, TRUE); 
} 

/** 
* Resets the Captcha response counters and removes the count sessions. 
* 
* @return void 
*/ 
public function reset_count() 
{ 
    $this->valid_count(0); 
    $this->valid_count(0, TRUE); 
} 

/** 
* Checks whether user has been promoted after having given enough valid responses. 
* 
* @param integer valid response count threshold 
* @return boolean 
*/ 
public function promoted($threshold = NULL) 
{ 
    // Promotion has been disabled 
    if (self::$config['promote'] === FALSE) 
     return FALSE; 

    // Use the config threshold 
    if ($threshold === NULL) 
    { 
     $threshold = self::$config['promote']; 
    } 

    // Compare the valid response count to the threshold 
    return ($this->valid_count() >= $threshold); 
} 

/** 
* Returns or outputs the Captcha challenge. 
* 
* @param boolean TRUE to output html, e.g. <img src="#" /> 
* @return mixed html string or void 
*/ 
public function render($html = TRUE) 
{ 
    return $this->driver->render($html); 
} 

/** 
* Magically outputs the Captcha challenge. 
* 
* @return mixed 
*/ 
public function __toString() 
{ 
    return $this->render(); 
} 

} //结束验证码类

+1

看起来就像你有一个验证码参考你形成是无处可寻。你能发布你的代码吗? – Roger 2012-04-12 13:20:39

+0

您能否添加一些细节,如:您使用的是哪个版本的Kohana?,您用什么发送电子邮件?,您如何验证captcha? – 2012-04-12 18:42:09

+0

我不太确定去哪里看。该框架是kohana,并有一个名为“Captcha.php”的php文件 – 2012-04-12 19:43:59

回答

0

从提供的小细节我想你使用的是来自Kohana中的的I18n库网站的国际化。另一种选择是您的网站使用Kohana消息来显示表单错误。

Validation类在生成验证错误时在内部使用__()函数。我认为您没有关于APPPATH/messages/contact/captcha.php中指定的密钥valid的消息。

您应该尝试调查更多关于如何处理表单以及是否生成一些验证错误。验证码验证可能存在错误,尽管看起来没有错误,但可能存在错误消息,并且只能显示错误消息。

+0

这是在核心 - $ Id:Kohana.php 3917 2009-01-21 03:06:22Z zombor $ ...我认为这是版本号 – 2012-04-12 19:52:39

0
class Contact_Controller extends Main_Controller 
{ 
    function __construct() 
    { 
     parent::__construct(); 
    } 

    public function index() 
    { 

     $this->template->header->this_page = 'contact'; 
     $this->template->content = new View('contact'); 

     $this->template->header->page_title .= Kohana::lang('ui_main.contact').Kohana::config('settings.title_delimiter'); 

     // Setup and initialize form field names 
     $form = array (
      'contact_name' => '', 
      'contact_email' => '', 
      'contact_phone' => '', 
      'contact_subject' => '', 
      'contact_message' => '', 
      'captcha' => '' 
     ); 

     // Copy the form as errors, so the errors will be stored with keys 
     // corresponding to the form field names 
     $captcha = Captcha::factory(); 
     $errors = $form; 
     $form_error = FALSE; 
     $form_sent = FALSE; 

     // Check, has the form been submitted, if so, setup validation 
     if ($_POST) 
     { 
      // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things 
      $post = Validation::factory($_POST); 

      // Add some filters 
      $post->pre_filter('trim', TRUE); 

      // Add some rules, the input field, followed by a list of checks, carried out in order 
      $post->add_rules('contact_name', 'required', 'length[3,100]'); 
      $post->add_rules('contact_email', 'required','email', 'length[4,100]'); 
      $post->add_rules('contact_subject', 'required', 'length[3,100]'); 
      $post->add_rules('contact_message', 'required'); 
      $post->add_rules('captcha', 'required', 'Captcha::valid'); 

      // Test to see if things passed the rule checks 
      if ($post->validate()) 
      { 
       // Yes! everything is valid - Send email 
       $site_email = Kohana::config('settings.site_email'); 
       $message = Kohana::lang('ui_admin.sender').": " . $post->contact_name . "\n"; 
       $message .= Kohana::lang('ui_admin.email').": " . $post->contact_email . "\n"; 
       $message .= Kohana::lang('ui_admin.phone').": " . $post->contact_phone . "\n\n"; 
       $message .= Kohana::lang('ui_admin.message').": \n" . $post->contact_message . "\n\n\n"; 
       $message .= "~~~~~~~~~~~~~~~~~~~~~~\n"; 
       $message .= Kohana::lang('ui_admin.sent_from_website'). url::base(); 

       // Send Admin Message 
       email::send($site_email, $post->contact_email, $post->contact_subject, $message, FALSE); 

       $form_sent = TRUE; 
      } 
      // No! We have validation errors, we need to show the form again, with the errors 
      else 
      { 
       // repopulate the form fields 
       $form = arr::overwrite($form, $post->as_array()); 

       // populate the error fields, if any 
       $errors = arr::overwrite($errors, $post->errors('contact')); 
       $form_error = TRUE; 
      } 
     } 

     $this->template->content->form = $form; 
     $this->template->content->errors = $errors; 
     $this->template->content->form_error = $form_error; 
     $this->template->content->form_sent = $form_sent; 
     $this->template->content->captcha = $captcha; 

     // Rebuild Header Block 
     $this->template->header->header_block = $this->themes->header_block(); 
     $this->template->footer->footer_block = $this->themes->footer_block(); 
    } 
} 
+0

这是代码的意见形式 – 2012-04-16 10:18:44

+0

编辑您的问题与这个信息并删除这个非答案 – random 2012-04-21 00:47:22

0

我的问题已解决!

我的电子邮件服务器设置不正确。我解决了后缀的问题,现在的评论形式,它应该工作,

感谢所有谁回答,

罗布