Welcome Guest, Not a member yet? Register   Sign In
Sending Codeigniter Views As HTML Content Using PHPMailer


The following function grabs the content from view with html forms and emails the posted content to the administrator email. The configuration is fetched from a config email file under the config folder.

It can send normal content which are coded directly within the function but unable to send an external view in the email.

If the isHTML is set to true, the function goes through an infinite loops and crash.

Anyone faced similar problem as mentioned ? What's the best solutions to fix this?

I know CI got built in email class, but for some reason I had to use the PHPmailer class.

function sandbox()
//Loading the class and config file
$this->config->load('mail', TRUE);
    //Create an email object
    $mail = new PHPMailer();

//Email default config from the config file.
$mail->SMTPAuth   = $this->config->item('SMTPAuth', 'mail');
$mail->Host       = $this->config->item('Host', 'mail');
$mail->Port       = $this->config->item('Port', 'mail');
$mail->Username   = $this->config->item('Username', 'mail');
$mail->Password   = $this->config->item('Password', 'mail');

//Mail Content
//Email From
$mail->SetFrom($this->input->post('email'), $this->input->post('name'));
//Email Reply To
$mail->AddReplyTo($this->input->post('email'), $this->input->post('name'));
//Email Subject
$mail->Subject    = "Contact Us";
//Email Content From View
$content = file_get_contents($this->load->view('mail/contact_us', '' , TRUE));
//Another Email Content

$mail->AddAddress($this->config->item('mailToEMAIL', 'mail'), $this->config->item('mailToNAME', 'mail'));

   // if the mail is sent or did not sent...
    $this->session->set_flashdata('successMSG','Email Sent');

    $this->session->set_flashdata('errorMSG','Unable to send the email');

Messages In This Thread
Sending Codeigniter Views As HTML Content Using PHPMailer - by El Forum - 08-12-2012, 02:03 AM

Theme © iAndrew 2016 - Forum software by © MyBB