【问题标题】:How do i email from php form我如何从 php 表单发送电子邮件
【发布时间】:2015-10-25 17:31:00
【问题描述】:

我正在尝试将数组中的姓名、电子邮件、公司、电话和国家/地区插入电子邮件消息中,但我得到的只是一封空电子邮件。 主题,往返于所有作品,但我没有收到电子邮件中的消息。 谁能告诉我我做错了什么?

<? php
public function contact_mail() {

    $data = array(
        'name' => $this->input->post('name'),
        'email' => $this->input->post('email'),
        'company' => $this->input->post('company'),
        'phone' => $this->input->post('phone'),
        'country' => $this->input->post('country')
    );

    $success = $this->data->save_contact_info($data);
    if ($success) {
        $data = array('success_message' => 'Thank you. We\'ll be in touch.');
        $this->load->view('ajax/json', array('json' => $data));

        $this->load->library('email');
        $config['mailtype'] = 'html';
        $this->email->initialize($config);
        $this->email->from("noreply@example.com", "Example Notification Service");
        $this->email->to(array('mha@example.com'));
        $this->email->subject('Contact form');
        $this->email->message($data);
        $this->email->send();

    }
    else {
        $this->load->view('ajax/error', array('error_msg' => 'Please fill out all fields.'));
    }
}
?>

【问题讨论】:

  • 原来它工作正常,但电子邮件中的消息只是“1”。我如何从表格中获取电子邮件信息是姓名、电子邮件、公司、电话和国家/地区?

标签: php ajax codeigniter email


【解决方案1】:

改变这一行:

$this->load->view('ajax/json', array('json' => $data));

到这里:

$view = $this->load->view('ajax/json', array('json' => $data));

然后,不是通过 $data 发送只是一个 array,而是通过 $view 发送,它是包含数组的 HTML。

另外,您使用$data 来获取所有POST 变量,但稍后使用data 来设置flash 消息。

我不确定您是否要覆盖 $data,但最好为不同的事物保持不同的变量名称。

【讨论】:

  • 感谢您的回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-22
  • 2016-01-12
  • 2014-06-09
  • 1970-01-01
  • 2014-05-29
  • 1970-01-01
相关资源
最近更新 更多