I'm following a tutorial to send emails using gmail, however what I get is a page that just hangs and doesn't even load an error. I'm using MAMP so that may be a reason why it isnt working.
class Email extends CI_Controller{
public function __construct()
{
parent::__construct();
}
function index(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email',
'smtp_pass' => 'pass'
);
$this->load->library('email',$config);
$this->email->set_newline("/r/n");
$this->email->from('email', 'George');
$this->email->to('email');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
if($this->email->send()){
echo 'Your message was sent';
}else{
show_error($this->email->print_debugger());
}
}
}
in your php.ini file uncomment extension=php_openssl.dll
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser@gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', config);
$this->email->from('email@gmail.com', 'George');
$this->email->to('email@gmail.com');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
$this->email->send();
echo $this->email->print_debugger();
Hope this will work
The line causing problems is:
$this->email->set_newline("/r/n");
Remove it and try sending the email.
I just did this successfully myself, but through sending all values in config/email.php instead. That part shouldn't matter.
Well basicly are you trying to send through a @gmail account or your own domain? If you're trying to go through your own domain, you need to change the DNS to relevant google settings:
Create MX Records
MAMP does not ship with the openssl extension, but you can create it yourself. For details see this tutorial
Start by posting using the standard smtp ports and make sure that works using the config below:
function index(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.googlemail.com',
'smtp_port' => 25,
'smtp_user' => 'email',
'smtp_pass' => 'pass'
);
$this->load->library('email',$config);
$this->email->from('email', 'George');
$this->email->to('email');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
$this->email->send();
}
Once you've tried that and it's all working have a read through this:
http://codeigniter.com/forums/viewthread/84689/