1
我試圖從我的網站的聯繫表格發送電子郵件。 我使用笨和引導,用jQuery驗證,下面的代碼:CodeIgniter不在本地主機發送電子郵件
HTML,代碼視圖名爲 「bootstrap.php中」:
<div class="col-sm-12 contact-form" >
<form class="form-inline" id="validate_form" role="form" method="POST" action="index.php/site/send_email">
<div class="form-group">
<input type="text" class="form-control" id="form_name" name="form_name" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control" id="form_email" name="form_email" placeholder="Email">
</div>
<div class="form-group">
<textarea class="form-control animated-textarea" id="form_message" name="form_message" placeholder="Message" cols="30" ></textarea>
</div>
<button type="submit" id="form_submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
</div>
的Javascript:
$('#validate_form').validate({
errorElement: 'span',
rules:{
form_name:{
required:true,
minlength:2
},
form_email:{
required:true,
email:true
},
form_message:{
required:true,
minlength:20,
maxlength:500
}
},
messages:{
form_name:{
required:"!",
minlength:"!",
},
form_email:{
required:"!",
email:"!",
},
form_message:{
required:"!",
minlength: "!",
maxlength: "!",
}
},
});
控制器:
<?php
class Site extends CI_Controller{
public function index()
{
$this->show();
}
public function show()
{
$this->lang->load('main');
$this->load->view('bootstrap');
}
public function send_email()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '', // have my email here
'smtp_pass' => '', // and my password here
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$name = $this->input->post('form_name', TRUE);
$email = $this->input->post('form_email', TRUE);
$message = $this->input->post('form_message', TRUE);
$this->email->from($email, 'Teste');
$this->email->to('');//my mail here
$this->email->subject('Inside Visions Contact Message');
$this->email->message($message);
$this->email->send();
if ($this->email->send()){
$this->load->view('bootstrap');
}
else {
echo 'error';
}
}
}
?>
缺失的是什麼?它向我展示了錯誤,當它沒有錯誤時,它刷新頁面,但在我的郵箱中沒有郵件。
您的**'localhost'**上是否安裝了**郵件服務器**和**'running'**? – reikyoushin
爲什麼我讀,用於在localhost發送電子郵件我只需要$ config數組,我有 – user3088049
你需要一個郵件服務器發送郵件..我相信你的配置假設你有一個在你的服務器上運行.. – reikyoushin