Codeigniter $ this-> email-> send () does not work while mail () does

I cannot understand why, if I try to use the CI email class, it does not send emails, and if I use the PHP mail () native class, it works.

It should be noted that sometimes I get "sent by e-mail", although it is not actually sent, and sometimes I get the error message "my server is not configured."

I tried to figure out how to configure it, but ... nothing ...

The following controller code:

if($this->form_validation->run()){ //Set Language $this->lang->load('site', $this->session->userdata('lang')); //Random key $user_valid_key = md5(uniqid()); //Prepare email $this->load->library('email', array('mailtype' => 'html')); $this->email->from($this->config->item('email_signup_from'), 'Wondermark.net'); $this->email->to($this->input->post('email')); $this->email->subject($this->lang->line('email_signup_subject')); //Format mail con %s per inserire i campi necessari $signup_msg = sprintf($this->lang->line('email_signup_message'), $this->input->post('fname'), base_url().'main/signup_confirm/'.$user_valid_key); $this->email->message((string)$signup_msg); if($this->email->send()){ //TODO: load view... echo "email sent"; }else{ $to = $this->input->post('email'); mail($to, 'test', 'Other sent option failed'); echo $this->input->post('email'); show_error($this->email->print_debugger()); } //TODO: Add to db }else{ // Form validation failed } 
+7
php email codeigniter
source share
5 answers

Use this installation letter.

 $this->load->library('email'); $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; $config['smtp_port'] = '465'; $config['smtp_timeout'] = '7'; $config['smtp_user'] = ' sender_mailid@gmail.com '; $config['smtp_pass'] = 'password'; $config['charset'] = 'utf-8'; $config['newline'] = "\r\n"; $config['mailtype'] = 'text'; // or html $config['validation'] = TRUE; // bool whether to validate email or not $this->email->initialize($config); $this->email->from(' sender_mailid@gmail.com ', 'sender_name'); $this->email->to(' recipient@gmail.com '); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); $this->email->send(); echo $this->email->print_debugger(); 
+20
source share

I ran into this problem and found the following solution. Just a small change in the email configuration, and it works 100%:

 $config['protocol'] = 'ssmtp'; $config['smtp_host'] = 'ssl://ssmtp.gmail.com'; 
+5
source share

Codeigniter User Guide: http://ellislab.com/codeigniter/user-guide/libraries/email.html

This setup works for me:

 $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'Your SMTP Server', 'smtp_port' => 25, 'smtp_user' => 'Your SMTP User', 'smtp_pass' => 'Your SMTP Pass', 'mailtype' => 'html' ); $this->load->library('email', $config); $this->email->set_newline("\r\n"); //Add file directory if you need to attach a file $this->email->attach($file_dir_name); $this->email->from('Sending Email', 'Sending Name'); $this->email->to('Recieving Email address'); $this->email->subject('Email Subject'); $this->email->message('Email Message'); if($this->email->send()){ //Success email Sent echo $this->email->print_debugger(); }else{ //Email Failed To Send echo $this->email->print_debugger(); } 
+2
source share

After the same problem, for a couple of hours, I decided to change my config to send via another server. My source server for some reason would send to some addresses, but not to others (in the same domain). As soon as I switched to sendgrid, it worked as expected.

If you do not get the expected results, try a different SMTP server. The problem may not be in your code ...

+1
source share

I had the same problem and am trying to use the code lower than the Codeignitor mail function.

 mail(' mypersonalmail@domainserver.com ' , 'Test', 'Test Email'); 

It works, and mail is sent to the email address. This mail sent the already created email address (as I think). In my case, this is:

 gtt28651ff@p3plcpnl0552.srod.ahx3.domainserver.com 

So, I copy this email address and try it using the code below.

 $this->email->from(' gtt28651ff@p3plcpnl0552.srod.ahx3.domainserver.com ', 'www.domainserver.com'); 

And it works great. It seems that some servers need an already created email address to send email, while others do NOT.

Hope this is clear and helpful.

+1
source share

All Articles