2

I am using MAMP and CodeIgniter 2.1.3(the latest) and trying to send an email. I have read various tutorials and as far as I can see my code has no errors in it. I need some help deciphering where the problem is as every time I run the function, local or when I have uploaded it, I receive only a blank page. Nothing is being printed on screen at all.

I have tried setting out the $config array both ways I know and nothing changes. I.e. $config['protocol'] = 'smtp'; and $config = Array( 'protocol' => 'smtp', 'smtp_host => 'ssl://smtp.googlemail.com');

I can't understand why its not working, I've been through the email library and I have all the config written right. Is there some syntax error that I cannot see?

<?php 

class Email extends CI_Controller
{
    function __construct()
    {
        parent::Controller();
    }

    function index()
    {


        $config['protocol'] = 'smtp';
        $config['mail_path'] = 'ssl://smtp.googlemail.com';
        $config['smtp_host'] = 'ssl://smtp.googlemail.com';
        $config['smtp_port'] = 465;
        $config['smtp_user'] = 'MYEMAIL@gmail.com'
        $config['smtp_pass'] = 'PASSWORD';

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");

    $this->email->from('MYEMAIL@gmail.com', 'THIS GUY');
    $this->email->to('MYEMAIL@gmail.com');
    $this->email->subject('Email test bitches');
    $this->email->message('This is working, I hope');

        if($this->email->send())
        {
            echo "Da email, da email, wut wut da emails";
        }else{
            show_error($this->email->print_debugger());

        }
    }
}

The error that I have got to print on screen is as follows

Parse error: syntax error, unexpected '$config' (T_VARIABLE) in /Applications/MAMP/htdocs/codeigniter/application/controllers/email.php on line 18

So then I saw that it lacked a ; and I put it in but now the page doesn't load :/. Added ssl:// and now I have an error report from Google. At least I can work with this.

Thank you :)

Adam Brown
  • 2,812
  • 4
  • 28
  • 39

1 Answers1

2

You should get error. Probably you are in production environment and the error reporting is turned off. The problem is with your constructor. Change it with this-

function __construct()
{
    parent::__construct();
}

Turn error reporting on. Check how

EDIT:

You forgot to put semicolon in this line

$config['smtp_user'] = 'MYEMAIL@gmail.com'
Community
  • 1
  • 1
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
  • Nope :( this hasn't helped, and my environment is already defined as development and `error_reporting(E_ALL)` also :( – Adam Brown May 26 '13 at 18:09
  • Have you changed the constructor? With your previous constructor, you should get this error `Fatal error: Call to undefined method CI_Controller::Controller() in ...` – sakibmoon May 26 '13 at 18:11
  • Yep changed the Constructor. Actually I added another line into the error reporting and I'm now getting an error finnally!! I'll put it in the question – Adam Brown May 26 '13 at 18:13
  • Thank you for your help. It was the constructor part. But I had tried to change so many things it took a while to get back to it – Adam Brown May 26 '13 at 18:22