在這段代碼中,我創建了一個簡單郵件功能的驗證碼,它不起作用。郵件功能在CodeIgniter中不起作用
當我點擊註冊時,我想發送一封郵件給收件人。
控制器:test.php的
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url', 'captcha'));
$this->load->model('Fetch_data');
$this->session->set_flashdata('');
}
public function login()
{
if($this->input->post('signup'))
{
$data = array(
'firstname' => $this->input->post('fname'),
'lastname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('mobile'),
'city' => $this->input->post('city'),
'interest_field' => $this->input->post('interest_field'),
'password' => $this->input->post('password')
);
$this->db->select('*');
$this->db->from('students');
$where = "email = '".$this->input->post('email')."'";
$this->db->where($where);
$query = $this->db->get();
if ($query->num_rows() > 1)
{
$this->session->set_flashdata('message', '<p style="color: red;font-weight: bold;">Email Id already exist. Please login with diffrent email id.</p>');
}
else
{
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if($inputCaptcha === $sessCaptcha)
{
$this->db->insert('students',$data);
$to = $this->input->post('email');
$subject = "testing";
$txt = "Hello world!";
$headers = "From: [email protected]";
$success = mail($to,$subject,$txt,$headers);
if($success)
{
$this->session->set_flashdata('message', '<p style="color: #89c343;font-weight: bold;">Please check your mail for complete registration.</p>');
}
}
else
{
$this->session->set_flashdata('message', '<p style="color: red;font-weight: bold;">Captcha code was not match, please try again.</p>');
}
}
}
$config = array(
'img_path' => 'resources/img/captcha_images/',
'img_url' => base_url().'resources/img/captcha_images/',
'img_width' => '200',
'img_height' => 40,
'word_length' => 8,
'font_size' => 16
);
$captcha = create_captcha($config);
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode',$captcha['word']);
$data['captchaImg'] = $captcha['image'];
$this->load->view('login',$data);
}
}
觀點:login.php中
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="fname" id="fname" placeholder="Your First Name" class="text-line"/>
</div>
<div class="form-group">
<input type="text" name="lname" id="lname" placeholder="Your Last Name" class="text-line"/>
</div>
<div class="form-group">
<input type="text" name="email" id="email" placeholder="Your Email" class="text-line"/>
</div>
<div class="form-group">
<p id="captImg"><?php echo $captchaImg; ?></p>
<input type="text" name="captcha" value="" class="captcha" placeholder="Enter Image Inputs"/>
<br/>
<br/>
<a href="javascript:void(0);" class="refreshCaptcha" >Can't Read Please Refersh Image</a>
</div>
<div class="form-group">
<input type="submit" name="signup" id="signup" value="Sign Up" class="btn btn-warning"/>
</div>
</form>
驗證碼驗證工作@Regolith但是電子郵件仍然沒有工作 – omkara
你在'localhost'工作?在本地服務器的正常配置下,電子郵件服務器不工作。如果可以,請在實時服務器中檢查。 – Regolith
感謝您的回覆:) – omkara