0

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

1 回答 1

1

反之亦然:_

$this->email->from($res['sender_email'], $res['sender_name']);

你不小心放错了属性。这同样适用于您的表单标签。

…&sender_name=mrabe%40example.com&sender_email=Marvin+Test

值传输错误。

如果您使用的电子邮件地址不是来自您的服务器,那么 SMTP 服务器可能会禁止发送。服务器正在使用发件人策略框架。将电子邮件地址替换为from()来自您服务器的真实电子邮件地址或附加 .

于 2013-02-13T19:37:41.197 回答