就像标题说的那样,在我的页面上,我有一个包含电子邮件、姓名和消息字段的联系表。出于某种原因,如果在名称字段中输入了 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);
}