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

[eluser]ariffin246[/eluser]
Hello,

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.

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


//Email default config from the config file.
$mail->IsSMTP();
$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));
$mail->MsgHTML($content);
//Another Email Content
$mail->MsgHTML("test");

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


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

    }
   else
    {
    $this->session->set_flashdata('errorMSG','Unable to send the email');
    redirect('contact_us');
    }
    
  
  
  
}


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