注册电子邮件不会发送代码点火器

时间:2016-01-18 04:43:55

标签: php codeigniter email

我写了一个函数,使用他们在注册表单上发送的电子邮件向用户发送电子邮件。但是,在测试时,电子邮件不会转到输入的电子邮件地址。我通过将电子邮件cc发送到一个有效的地址来检查以确保该功能正常工作。以下是该功能。

查看

    <div class="col-lg-4 col-lg-offset-4">
    <h2>Hello There</h2>
    <h5>Please enter the required information below.</h5>     
<?php 
    $fattr = array('class' => 'form-signin');
    echo form_open('/main/register', $fattr); ?>
    <div class="form-group">
      <?php echo form_input(array('name'=>'firstname', 'id'=> 'firstname', 'placeholder'=>'First Name', 'class'=>'form-control', 'value' => set_value('firstname'))); ?>
      <?php echo form_error('firstname');?>
    </div>
    <div class="form-group">
      <?php echo form_input(array('name'=>'lastname', 'id'=> 'lastname', 'placeholder'=>'Last Name', 'class'=>'form-control', 'value'=> set_value('lastname'))); ?>
      <?php echo form_error('lastname');?>
    </div>
    <div class="form-group">
      <?php echo form_input(array('name'=>'email', 'id'=> 'email', 'placeholder'=>'Email', 'class'=>'form-control', 'value'=> set_value('email'))); ?>
      <?php echo form_error('email');?>
    </div>
    <?php echo form_submit(array('value'=>'Sign up', 'class'=>'btn btn-lg btn-primary btn-block')); ?>
    <?php echo form_close(); ?>
</div>

控制器

 public function register()
    {

        $this->form_validation->set_rules('firstname', 'First Name', 'required');
        $this->form_validation->set_rules('lastname', 'Last Name', 'required');    
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');    

        if ($this->form_validation->run() == FALSE) {   
            $this->load->view('header');
            $this->load->view('register');
            $this->load->view('footer');
        }else{                
            if($this->user_model->isDuplicate($this->input->post('email'))){
                $this->session->set_flashdata('flash_message', 'User email already exists');
                redirect(site_url().'main/login');
            }else{

                $clean = $this->security->xss_clean($this->input->post(NULL, TRUE));
                $id = $this->user_model->insertUser($clean); 
                $token = $this->user_model->insertToken($id);                                        

                $qstring = base64_encode($token);                    
                $url = site_url() . 'main/complete/token/' . $qstring;
                $link = '<a href="' . $url . '">' . $url . '</a>'; 


                $message = '';                     
                $message .= '<strong>You have signed up with our website</strong><br>';
                $message .= '<strong>Please click:</strong> ' . $link;                          

                $config = array(
                    'protocol' => 'smtp',
                    'smtp_host' => 'host',
                    'smtp_port' => 'port',
                    'smtp_user' => 'username',
                    'smtp_pass' => 'password');

                $this->load->library('email', $config);

                $this->email->set_newline("/r/n");

                $this->email->from('***@****.com', 'High Ball Run8');
                $this->email->to(set_value("email"));
                $this->email->cc('****@*****.com');

                $this->email->subject('Highball Registration Email Activation');
                $this->email->message($message);
                if ($this->email->send()) {
                       redirect(site_url());
                   }else{
                    show_error($this->email->print_debugger());
                   }
                exit;

2 个答案:

答案 0 :(得分:0)

请检查以下工作代码

function sendMail()
{
    $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'xxx@gmail.com', // change it to yours
  'smtp_pass' => 'xxx', // change it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);

        $message = '';
        $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xxx@gmail.com'); // change it to yours
      $this->email->to('xxx@gmail.com');// change it to yours
      $this->email->subject('Resume from JobsBuddy for your Job posting');
      $this->email->message($message);
      if($this->email->send())
     {
      echo 'Email sent.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }

}

Reference

答案 1 :(得分:0)

你试过吗

var_dump(set_value("email")); exit();

看看输出是什么?如果硬编码的CC工作正常,你可能无法正确地解决问题。