I'm trying recently to write a form for sending emails in codeigniter and it shows a problem with sending.
Failed to authenticate password. Error: 535-5.7.8 Username and Password not >accepted. Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257 >2sm864121lja.37 - gsmtp Unable to send email using PHP SMTP. Your server might not be configured to >send mail using this method.
I'm using the same password as to gmail account. In php.ini I set:
sendmail_path = "\"E:\xampp\sendmail\sendmail.exe\" -t"
instead
;sendmail_path = "\"E:\xampp\sendmail\sendmail.exe\" -t"
and in sendmail.ini I set up a auth_username, auth_password, smtp_port and smtp_server.
it is my view(myform.php):
<?php echo validation_errors(); ?>
<?php $this->load->helper("form");
echo form_open('form'); ?>
<h5>Tytul</h5>
<input type="text" name="topic" value="<?php echo set_value('topic'); ?>"
size="50" />
<h5>Text</h5>
<input type="text" name="text" value="<?php echo set_value('text'); ?>"
size="50" />
<h5>Nick</h5>
<input type="text" name="username" value="<?php echo set_value('username');
?>" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="<?php echo set_value('email'); ?>"
size="50" />
<div><input type="submit" value="Submit" /></div>
</form> <?php echo $this->session->flashdata('msg'); ?>
It is my controller (form.php):
<?php
class Form extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index()
{
//set validation rules
$this->form_validation->set_rules('username', 'username', 'required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('email', 'Emaid ID', 'required|valid_email');
$this->form_validation->set_rules('text', 'text', 'required');
$this->form_validation->set_rules('topic', 'topic', 'required');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('myform');
}
else
{
//get the form data
$name = $this->input->post('username');
$from_email = $this->input->post('email');
$subject = $this->input->post('topic');
$message = $this->input->post('text');
//set to_email id to which you want to receive mails
$to_email = 'email@gmail.com';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'email@gmail.com';
$config['smtp_pass'] = 'password';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
//$this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('form/index');
}
else
{
//error
echo $this->email->print_debugger();
}
}
}
}
?>