Hello,
Using codeigniter 2.1.2
I am developing a site where I email a few forms with codeingiter email library.
Everything worked find until today when one of the emails gives me an error.
I didn’t change anything in the way I am sending the emails, but this one just fails.
So, I did some research and found the PHPMailer plugin.
Trying to work with this plugin gives me errors as well.
So I have a few questions.
I have downloaded the PHPMailer package.
I put everything in: libraries/phpmailer/
I change the file name: class.phpmailer.php to phpmailer.php
In this file I added these lines:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$CI =& get_instance();
$CI->load->config('phpmailer', TRUE);First general question here:
I use ion_auth in my site, when I look at their library file I don’t see they use: $CI =& get_instance() they just use the normal $this, so why is it working for them and not for me?
Then I created a file in: config/development/phpmailer.php: (My ENVIRONEMENT is set to development)
$config['SMTPAuth'] = true; // enable SMTP authentication
$config['SMTPSecure'] = "ssl"; // sets the prefix to the servier
$config['Host'] = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$config['Port'] = 465; // set the SMTP port for the GMAIL server
$config['Username'] = "[email protected]"; // GMAIL username
$config['Password'] = "mypassword"; // GMAIL passwordSecond general question:
Reading the codeigniter user guide on create libraries:
You can also pass parameters stored in a config file. Simply create a config file named identically to the class file name and store it in your application/config/ folder
Did that, so why do I still need to load the config file?
I have created a helper file: helpers/send_email_helper.php
<?php
function sendEmail($fromEmail, $fromName, $replyTo, $replyToName, $emailTo, $emailToName, $subject, $body, $bodyData)
{
$CI =& get_instance();
$CI->load->library('phpmailer/phpmailer');
$mail = new PHPMailer();
$body = $this->load->view($body, $bodyData, TRUE);//file_get_contents($body);
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SetFrom($fromEmail, $formName);
$mail->AddReplyTo($replyTo, $replyToName);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address = $emailToName . ' ' . $emailTo;
$mail->AddAddress($emailTo, $emailToName);
return $mail->Send();
}In my conroller I code:
$this->load->helper('send_email');
$subject = 'Your free business listing with Phonebook';
$body = 'phonebook/emails/submit';
$bodyData = $this->data['ad'];
$emailFrom = $this->config->item('listingemail', 'email');
$emailTo = $this->data['ad']->email;
$emailToName = $this->data['ad']->firstname . ' ' . $this->data['ad']->surname;
$emailSent = sendEmail($emailFrom, 'Phonebook', $emailFrom, 'Phonebook', $emailTo, $emailToName, $subject, $body, $bodyData);Submitting the form I get this error:
Parse error: syntax error, unexpected T_VARIABLE in C:\sites\thinklocal\application\libraries\phpmailer\phpmailer.php on line 225
Line 225 in phpmailer.php is:
public $Host = $CI->config->item('Host');Why do I get this error?
Can someone please help?