Sending email to CodeIgniter via gmail

I am following a tutorial on sending emails using gmail, however what I get is a page that just freezes and doesn't even load an error. I use MAMP, so this may be the reason why it does not work.

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()); } } } 
+4
source share
5 answers

in the extension php.ini 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 it works

+7
source

The problem that causes the following problems:

 $this->email->set_newline("/r/n"); 

Delete it and try sending an email.

0
source

I did this successfully myself, but instead sent all the values ​​to config / email.php. This part does not matter.

Ok, are you trying to send an account or your own domain via @gmail? If you are trying to go through your own domain, you need to change the DNS to the appropriate google settings:

Create MX Records

0
source

MAMP does not come with the openssl extension, but you can create it yourself. See this tutorial for more details.

0
source

Start by publishing using the standard smtp ports and verify that this works using the configuration 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 letter"); $ this-> email-> message ("this is email content");

$ this-> email-> send (); }

Once you have tried this and it all works, read this:

http://codeigniter.com/forums/viewthread/84689/

-1
source

Source: https://habr.com/ru/post/1412381/


All Articles