在Codeigniter中发送电子邮件时无法刷新页面

时间:2017-11-22 01:39:18

标签: php codeigniter

我在我的codeigniter中有电子邮件表单,它正在成功发送电子邮件我只是在发送电子邮件时无法刷新页面,如果我发送电子邮件然后手动刷新页面它写了你的电子邮件已经已成功发送,用我的语言写成flashdata,这意味着一切正常我无法自动刷新页面,请帮忙。

这是我的联络管理员:

    class Contact extends CI_Controller {

  public function index()
  {
    $this->load->library('session');
    $this->load->library('email');
     $this->load->helper(array('form', 'url'));
      $this->load->library('form_validation');

      $data['title'] = "Contact";

    $this->load->view('templates/header', $data);
    $this->load->view('contact', $data);
    $this->load->view('templates/footer', $data);

  }

  public function sendmail1(){
    $this->load->library('email');
     $this->load->helper(array('form', 'url'));
      $this->load->library('form_validation');

$name = $this->input->post('contact-name');
$email = $this->input->post('contact-email');
$subject = $this->input->post('contact-subject');
$phone = $this->input->post('contact-phone');
$message = $this->input->post('contact-message');

$this->form_validation->set_rules('contact-name', 'სახელი', 'trim|required');
$this->form_validation->set_rules('contact-email', 'ელ-ფოსტა', 'trim|required');
$this->form_validation->set_rules('contact-phone', 'ტელეფონი', 'trim|required');
$this->form_validation->set_rules('contact-subject', 'წერილის თემა', 'trim');
$this->form_validation->set_rules('contact-email', 'ელ-ფოსტა', 'trim|required|valid_email');

if ($this->form_validation->run() == FALSE)
                {

                        $this->session->set_flashdata('warmatebulia', '<h5 style="color: red;">თქვენი წერილის გაგზავნა ვერ მოხერხდა.</h5>');
                        // after storing i redirect it to the controller
                        redirect(base_url().'contact', 'refresh');
                        return FALSE;
                }
                else {

$this->email->from($email, $name);
$this->email->to('info@mymail.com');

$this->email->subject($subject);
$this->email->message('ტელეფონის ნომერი:'.$phone.'<br />'.$message);

$this->email->send();



$this->session->set_flashdata('warmatebulia', '<h5 style="color: green;">თქვენი წერილი წარმატებით გაიგზავნა, მადლობა.</h5>');
// after storing i redirect it to the controller
redirect('', 'refresh');


  }
}
}

这是我在联系人视图页面上的表单:

<?php echo $this->session->flashdata('warmatebulia'); ?>
                    <?php
                    $attributes = array('class' => 'form-message', 'id' => 'quote-contact-request');
                    echo form_open('contact/sendmail1', $attributes);
                     ?>

                        <div class="form-results"></div>
                        <div class="form-group row">
                            <div class="form-field col-md-6 form-m-bttm">
                                <input name="contact-name" type="text" placeholder="სახელი *" class="form-control required">
                            </div>
                            <div class="form-field col-md-6">
                                <input name="contact-email" type="email" placeholder="ელ-ფოსტა *" class="form-control required">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-field col-md-6 form-m-bttm">
                                <input name="contact-phone" type="text" placeholder="ტელეფონის ნომერი*" class="form-control required">
                            </div>
                            <div class="form-field col-md-6">
                                <input name="contact-service" type="text" placeholder="წერილის თემა" class="form-control">
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="form-field col-md-12">
                                <textarea name="contact-message" placeholder="წერილი *" class="txtarea form-control required"></textarea>
                            </div>
                        </div>
                        <input type="submit" name="submit" value="გაგზავნა" class="btn solid-btn sb-h">
                    <?php echo form_close(); ?>

1 个答案:

答案 0 :(得分:0)

如果您需要在联系人页面中自动刷新成功消息,只需重定向到“联系人”的索引()功能即可。控制器。所以请这样做

$this->session->set_flashdata('warmatebulia', '<h5 style="color: green;">თქვენი წერილი წარმატებით გაიგზავნა, მადლობა.</h5>');
// after storing i redirect it to the controller
redirect('contact', 'refresh');