Welcome Guest, Not a member yet? Register   Sign In
Having trouble getting Email library to load
#1

[eluser]ihateregisteringforastupidforum[/eluser]
Using CI 1.7.2.

So I'm trying to make OpenVBX use CI's Email library, rather than php's own mail(), because on some hosts you cannot use that. No mail() function, just SMTP access.

I don't get why, but every time I try to add $this->load->library('email'); inside the function that is supposed to handle sending emails, I get a blank page. PHP just refuses to parse past that point. What am I missing?

Original Code:
Code:
function openvbx_mail($recipient, $subject, $template, $maildata = array())
{
    error_log('mailing');
    $path = APPPATH . 'views/emails/' . $template . '.php';
    $ci = &get;_instance();
    $domain = $_SERVER['HTTP_HOST'];
    $from_email = $ci->settings->get('from_email', $ci->tenant->id);
    if(empty($from_email))
    {
        $from_email = "$from <do-not-reply@$domain>";
    }
    
    $headers = "From: $from_email";

    /* Render the mail template */
    ob_start();
    extract($maildata);
    include($path);
    $message = ob_get_contents();
    ob_end_clean();

    if($ci->config->item('log_threshold') > 2)
    {
        error_log($message);
    }

    return mail($recipient, "[OpenVBX] " . $subject, $message, $headers);
}

So I can see that mail() can be replaced with $this->email->send();, or better off, to keep OpenVBX happy, I can do a if(!$this->email->send()Wink { return FALSE; } and include return TRUE; after.

Modified code:
Code:
function openvbx_mail($recipient, $subject, $template, $maildata = array())
{
    error_log('mailing');
    $path = APPPATH . 'views/emails/' . $template . '.php';
    $ci = &get;_instance();
    $domain = $_SERVER['HTTP_HOST'];
    $from_email = $ci->settings->get('from_email', $ci->tenant->id);
    if(empty($from_email))
    {
        $from_email = "$from <do-not-reply@$domain>";
    }
    
    $headers = "From: $from_email";

    /* Render the mail template */
    ob_start();
    extract($maildata);
    include($path);
    $message = ob_get_contents();
    ob_end_clean();

    if($ci->config->item('log_threshold') > 2)
    {
        error_log($message);
    }
    $this->load->library('email');
    $this->email->from($from_email, 'Company name here');
    $this->email->to($recipient);
    $this->email->subject($subject);
    $this->email->message($message);    
    if(!$this->email->send()) { return false; } else { return true; }
    //return mail($recipient, "[OpenVBX] " . $subject, $message, $headers);
}

Problem is, like I said, if I try to get the Email library loaded, I get a white page, php stops parsing.

I don't know why but I can't even get PHP to output all messages (and errors). I have the proper php.ini params set... beats me!

Any ideas would be appreciated - including helping me get to see the error messages at least. But trying to fix it blindly gets frustrating quick.
EDIT: I found config.php and noticed that I can turn debugging on there. It was overriding my php.ini.


Messages In This Thread
Having trouble getting Email library to load - by El Forum - 11-23-2010, 05:28 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 05:40 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 05:50 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 05:52 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 05:57 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 06:07 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 06:10 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 06:21 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 06:32 PM
Having trouble getting Email library to load - by El Forum - 11-23-2010, 06:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB