Sending Email Codeigniter Error

I am trying to send an email with my codeigniter project from my localhost, but it always shows this error:

220 mx.google.com ESMTP pp9sm11498734pbb.65 - gsmtp hello: 250-mx.google.com at your service, [202.43.95.33] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp from: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp to: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp data: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp 502 5.5.1 Unrecognized command. pp9sm11498734pbb.65 - gsmtp The following SMTP error was encountered: 502 5.5.1 Unrecognized command. pp9sm11498734pbb.65 - gsmtp Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. User-Agent: CodeIgniter Date: Mon, 19 Jan 2015 12:49:08 +0100 From: "andhika" < mytest@gmail.com > Return-Path: < mytest@gmail.com > To: coba@gmail.com Subject: =?utf-8?Q?test?= Reply-To: " mytest@gmail.com " < mytest@gmail.com > X-Sender: mytest@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: < 54bcef349adf6@gmail.com > Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit world 

This is my controller:

 $this->load->library('email'); $config = array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_user' => ' mytest@gmail.com ', 'smtp_pass' => 'youpassword', 'smtp_port' => '465' ); $this->email->initialize($config); $this->email->set_newline('\r\n'); $this->email->from(' mytest@gmail.com ', 'andhika'); $this->email->to(' coba@gmail.com '); $this->email->subject('test'); $this->email->message('world'); if ($this->email->send()){ echo 'Your e-mail has been sent'; } else{ show_error($this->email->print_debugger()); } 

This is in my php.ini setup: extension = php_openssl.dll

Any answer?

Thank you very much...

+6
source share
6 answers
 $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'username', 'smtp_pass' => 'password', 'mailtype' => 'html', 'charset' => 'iso-8859-1' ); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $result = $this->email->send(); 

Forum

fooobar.com/questions/92194 / ...

You can look at Mailgun . It looks easy to access and safe.

+2
source

If you use gmail, your gmail account must be modified to allow "access for less secure applications."

Information from gmail

Change account access for less secure applications
To protect Google Apps user accounts, we may block less secure applications from accessing Google Apps accounts. As a Google Apps User, you will see a "Password is incorrect" error when trying to log in. If so, you have two options:

Option 1: Switch to a more secure application that uses the latest security measures. All Google products, such as Gmail, use the latest security measures.

Option 2. Change the settings to allow applications to access your account. We do not recommend this option because it can help someone get into your account. if you want to allow access in any case, follow these steps: go to the "Less secure applications" section in the "My account" section. Next to โ€œAccess for less secure applications,โ€ select โ€œEnable.โ€
(Note for Google Apps users: this option is hidden if your administrator has blocked access to a less secure application account.) If you still cannot log into your account, enter the password incorrectly "error may be caused by another reason.

+1
source

In case anyone is interested, I found that using single quotes when setting newline , such as

 $this->email->set_newline('\r\n'); 

Throws a password error. For this, double quotes are needed:

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

Or it can be initialized in a $config array with double quotes:

 $config = array('newline' => "\r\n"); 
+1
source

Sending email with localhost using codeigniter:

If you use wampp / xampp, you need to configure the default email and username in the ini file of the send file and php ini file

The local host most of the time will not allow you to send mail if you have not configured the functions below, even if you configured the email in configingiter config.

Here's how you can set up sending mail on the local tutorial that I found to help me send email to the local host https://www.youtube.com/watch?v=TO7MfDcM-Ho

xammp / wamp Windows only

php folder go to php.ini found in line 1142 uncomment

; sendmail_path = "\" C: \ Xampp \ sendmail \ sendmail.exe \ "-t"

to

sendmail_path = "\" C: \ Xampp \ sendmail \ sendmail.exe \ "-t"

sendmail folder: sendmail.ini file

Add your details

line 14: smtp_server = gmail.com hostserver

line 18: smtp_port = 465 or 587

, and on lines 46 and 47 you need to add the username and

passwordauth_username = username@demo.com

auth_password = demo

Once all this is done, you can configure your mail code configuration, and then send mail. So far, sendmail.ini and php.ini have made changes to xampp / wampp

0
source

Sending email to Codeigniter is easy, you just need two steps:

Step # 1: create a controller

 <?php class Sendingemail_Controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->library('session'); $this->load->helper('form'); } public function index() { $this->load->helper('form'); $this->load->view('contact_email_form'); } public function send_mail() { $from_email = " email@example.com "; $to_email = $this->input->post('email'); //Load email library $this->load->library('email'); $this->email->from($from_email, 'Identification'); $this->email->to($to_email); $this->email->subject('Send Email Codeigniter'); $this->email->message('The email send using codeigniter library'); //Send mail if($this->email->send()) $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully."); else $this->session->set_flashdata("email_sent","You have encountered an error"); $this->load->view('contact_email_form'); } } ?> 

Step # 2: Create a View

 <html> <head> <title> Send Email Codeigniter </title> </head> <body> <?php echo $this->session->flashdata('email_sent'); echo form_open('/Sendingemail_Controller/send_mail'); ?> <input type = "email" name = "email" required /> <input type = "submit" value = "SEND MAIL"> <?php echo form_close(); ?> </body> </html> 

Step # 3: Make changes to the routes.php file in application / config / routes.php and add the following line to the end of the file:

 $route['email'] = 'Sendingemail_Controller'; 

See source for more details.

0
source

This works for me. I am running xampp windows.

I changed this part a bit

 php folder go to php.ini find on line 1142 uncomment ;sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t" 

to

 sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t" sendmail folder: sendmail.ini file 

Add your details

line 14: smtp_server=gmail.com hostserver

line 18: smtp_port=465 or 587 and on line 46 and 47 you need to add a username and

 passwordauth_username= ***@***.com //change to yours auth_password= ****** ////change to yours 

And I changed the gmail setting because I use gmail.

Change your settings to allow less secure applications to access your account. We do not recommend this option because it may make it easier for someone to enter your account.

If you want to allow access anyway, follow these steps:

  • Go to the "Less secure apps" section of "My Account."
  • Next to Access for less secure applications, select Enable.

(Note for Google Apps users: this option is hidden if your administrator has blocked access to your secure account less.)

If you still cannot log in to your account, the error is "invalid password"

0
source

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


All Articles