每当我尝试使用代码点火器发送电子邮件时,我都会收到错误消息。如果成功将欢迎电子邮件发送给用户,我有一个用户提交数据的表单。 将数据传递给控制器的Ajax文件
$("#submit-details").on("submit", function(){
$.ajax({
type: 'POST',
url: '<?php echo base_url() ?>'+'index.php/car/host ',
data: $("#submit-details").serialize(),
asyn: false,
}).done(function (data) {
console.log(data);
});
$("#submit-details")[0].reset();
$(".contact-form, .form-btns").hide();
$(".contact-confirm").show();
return false;
});
这是我的控制器。 公共功能主持人()
public function host()
{
$field = array(
'first_name' =>$this->input->post('first_name'),
'last_name' =>$this->input->post('last_name'),
'email_address' =>$this->input->post('email_address'),
'cities' =>$this->input->post('cities'),
'registration_number' =>$this->input->post('registration_number'),
'vehicle_make' =>$this->input->post('vehicle_make'),
'vehicle_model' =>$this->input->post('vehicle_model'),
'vehicle_registration_year' =>$this->input->post('vehicle_registration_year'),
);
$result = $this->Drivetrymodel->host($field);
$this->Drivetrymodel->welcomeHostEmail($this->input->post('email_address');); //
$msg['success'] = false;
if ($result) {
$msg['success'] = true;
}
echo json_encode($msg);
}
这是我的模特。
public function welcomeHostEmail(){
$from = "address@mail.com"; //senders email address
$subject = 'Welcome !'; //email subject
//sending email inside message body
$message = $this->load->view("frontend/emails/welcomehost", TRUE);
//config email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtpout.secure.net';
$config['smtp_port'] = '465';
$config['smtp_user'] = $from;
$config['smtp_pass'] = '*******'; //sender's password
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = 'TRUE';
$config['newline'] = "\r\n";
$this->load->library('email', $config);
$this->email->initialize($config);
//send email
$this->email->from($from);
$this->email->to($receiver);
$this->email->subject($subject);
$this->email->message($message);
// $this->email->send();
if($this->email->send()){
//for testing
echo "sent to: ".$receiver."<br>";
echo "from: ".$from. "<br>";
echo "protocol: ". $config['protocol']."<br>";
echo "message: ".$message;
return true;
}else{
echo "email send failed";
return false;
}
return $this->email->print_debugger();
}
如果我跑这是我得到的。
<h4>A PHP Error was encountered</h4>
<p>Severity: 4096</p>
<p>Message: Object of class CI_Loader could not be converted to string</p>
<p>Filename: libraries/Email.php</p>
<p>Line Number: 677</p>
如果我尝试通过传递空字符串将消息转换为字符串
$message = $this->load->view("frontend/emails/welcomehost", "", TRUE);
我收到新错误500(内部服务器错误)。