タイトルにあるように、私のページには、[メール]、[名前]、[メッセージ]フィールドのあるお問い合わせフォームがあります。何らかの理由で、[名前]フィールドに2つの単語を入力すると(たとえば、「John Doe」)、送信しようとするとエラーが発生します:\
誰か提案がありますか?
public function send_mail($res)
{
$this->load->library('email');
$config['protocol'] = 'SMTP';
$config['smtp_host'] = 'mail.something.com';
$config['smtp_user'] = 'email@something.com';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '25';
$this->email->initialize($config);
$this->email->from($res['sender_name'], $res['sender_email']);
$this->email->to($res['reciever']);
$this->email->reply_to($res['sender_email'], $res['sender_name']);
$this->email->subject('Message from website');
$this->email->message($res['message']);
if($this->email->send()) {
return true;
} else {
return false;
}
//configure mail agent...
}
private function get_email_address($email)
{
$this->load->model('main_model');
$email = $this->main_model->get_email($email);
return $email;
}
public function get_email_message()
{
//only ajax requests are allowed
if(!$this->input->is_ajax_request()) {
die();
}
$res['message'] = $this->input->post('message');
$res['reciever'] = $this->input->post('receiver');
$res['sender_name'] = $this->input->post('sender_name');
$res['sender_email'] = $this->input->post('sender_email');
$res['reciever'] = $this->get_email_address($res['reciever']);
$res = $this->send_mail($res);
$this->output->set_content_type('application/json')->set_output(json_encode($res));
}
PS私はエラーと検証のために見えるこのJSコードを見つけました、それが役立つかどうかわかりません:\
function createEmailElem() {
var parentElem = document.getElementById('contact_art');
var messageElem = document.createElement('textarea');
messageElem.id = 'email_message';
messageElem.style.cssText = "float:right;width: 93%;box-sizing: border-box;-moz-box-sizing: border-box;height:100px;";
//messageElem.id = "email_mess";
//messageElem.attributes.placeholder = 'Poruka';
//$('#email_mess').attr('placeholder') = 'test';
var nameDiv = document.createElement('div');
nameDiv.style.marginBottom = '5px';
var emailDiv = document.createElement('div');
emailDiv.style.marginBottom = '5px';
var labelMessage = document.createElement('label');
labelMessage.innerHTML = 'Poruka';
var labelName = document.createElement('label');
labelName.innerHTML = 'Vaš e-mail';
labelName.style.marginRight = '5px';
var labelEmail = document.createElement('label');
labelEmail.innerHTML = 'Vaše ime';
labelEmail.style.marginRight = '10px';
var nameElem = document.createElement('input');
nameElem.type = "text";
nameElem.name = "sender_name";
nameElem.id = "sender_name";
var emailElem = document.createElement('input');
emailElem.type = "text";
emailElem.name = "sender_email";
emailElem.id = "sender_email";
var buttonElem = document.createElement('input');
buttonElem.className = 'gradient-button';
buttonElem.id = 'email_send';
buttonElem.type = 'button';
buttonElem.value = 'Posalji';
buttonElem.style.cssText = "margin-top:10px;float: right;"
nameDiv.appendChild(labelName);
nameDiv.appendChild(nameElem);
emailDiv.appendChild(labelEmail);
emailDiv.appendChild(emailElem);
parentElem.appendChild(nameDiv);
parentElem.appendChild(emailDiv);
parentElem.appendChild(labelMessage);
parentElem.appendChild(messageElem);
parentElem.appendChild(buttonElem);
}
/*if email not found*/
function createNoticeElem() {
var parentElem = document.getElementById('contact_art');
var messageElem = document.createElement('p');
messageElem.innerHTML = 'The user didn\'t leave the e-mail address';
parentElem.appendChild(messageElem);
}
function sendEmail() {
if(ckeckEmail()) {
createEmailElem();
} else {
createNoticeElem();
}
}
function sendingSuccess() {
var parentElem = document.getElementById('contact_art');
var messageElem = document.createElement('p');
messageElem.innerHTML = 'Email was sended succesfuly!';
parentElem.appendChild(messageElem);
}
function sendingError() {
var parentElem = document.getElementById('contact_art');
var messageElem = document.createElement('div');
messageElem.className = 'alert alert-error';
messageElem.innerHTML = 'Error! Email was not sended!';
messageElem.style.width = '150px';
parentElem.appendChild(messageElem);
}
function phpSendingError() {
var parentElem = document.getElementById('contact_art');
var messageElem = document.createElement('div');
messageElem.className = 'alert alert-error';
messageElem.style.width = '250px';
messageElem.innerHTML = 'Error! Email was not sended! Something wrong with server';
parentElem.appendChild(messageElem);
}