Send Email with CodeIgnitor Email Library

I get an error whenever I try to send an email using the ignitor code. I have a form in which users send data if they successfully send a welcome letter to the user. Ajax file for transferring data to the controller

$("#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; }); 

Here is my controller. public function host ()

 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); } 

And here is my model.

 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 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(); } 

If I run, this is what I get.

 <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> 

if I try to convert the message to a string by passing an empty string like this

 $message = $this->load->view("frontend/emails/welcomehost", "", TRUE); 

I get a new error 500 (Internal server error).

+1
ajax php email codeigniter email-attachments
source share

No one has answered this question yet.

See similar questions:

10
Codeigniter sends an email with an attached file

or similar:

3998
How to check email address in JavaScript
3175
How to check email address with regex?
841
Sending Email in .NET via Gmail
812
What is the maximum length of a valid email address?
539
Submit Email Task
452
PHP mail function does not complete email sending
359
How to choose an authentication library for CodeIgniter?
one
WordPress AJAX sends email
0
Error sending smtp email using google and codeigniter
-one
Email is not sent using php mail function

All Articles