Php 使用CodeIgniter电子邮件库发送邮件

Php 使用CodeIgniter电子邮件库发送邮件,php,ajax,codeigniter,email,email-attachments,Php,Ajax,Codeigniter,Email,Email Attachments,每当我尝试使用CodeIgniter发送电子邮件时,都会出现错误。我有一个表单,用户提交数据,如果成功,欢迎电子邮件发送给用户。 将数据传递给控制器的Ajax文件 $("#submit-details").on("submit", function(){ $.ajax({ type: 'POST', url: '<?php echo base_url() ?>'+'inde

每当我尝试使用CodeIgniter发送电子邮件时,都会出现错误。我有一个表单,用户提交数据,如果成功,欢迎电子邮件发送给用户。 将数据传递给控制器的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 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(); 
}

我收到一个新的错误500(内部服务器错误)。

验证您的电子邮件模板,如“welcomehost.php”,并检查它是否为有效的html。(正常加载视图,按Ctrl+U并将代码复制粘贴到中)。。消除任何错误。在电子邮件配置中也使用$config['smtp_crypto']='ssl'只是一个建议:我不明白你为什么要调用模型来发送邮件。理想情况下,应该使用模型来查询数据库。@ValentinoPereira即使尝试了您的建议,仍然会出现错误500。请验证您的电子邮件模板,如“welcomehost.php”,并检查其是否为有效的html。(正常加载视图,然后按Ctrl+U组合键并将代码复制粘贴到中)。。消除任何错误。在电子邮件配置中也使用$config['smtp_crypto']='ssl'只是一个建议:我不明白你为什么要调用模型来发送邮件。理想情况下,应该使用模型来查询数据库。@ValentinoPereira即使尝试了您的建议,仍然会出现错误500。
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);