How to send mail with Codeigniter using the email library?

1

I am starting to program so I am making a web page but the query mail does not work, it does not send the description.

You could see my coding that is with Codeigniter and explain to me a bit that I'm wrong or because it does not work or is another kind of problem.

The hosting provider is called HOSTPER PERU.

This is my code:

//codigo del controllador 
public function  sendEmail(){
  $config = array(
  'protocol' => 'smtp',
  'smtp_host' => 'smtp.googlemail.com',
  'smtp_user' => '[email protected]', //El correo de la empresa
   'smtp_pass' => '', // Su Password de Gmail aqui
  'smtp_port' => '465',
  'smtp_crypto' => 'ssl',
  'mailtype' => 'html',
  'wordwrap' => TRUE,
  'charset' => 'utf-8'
  );

  $this->load->library('email', $config);
  $nombres = $this->input->post('nombres');
  $email = $this->input->post('email'); 
  $mensaje = $this->input->post('mensaje');  
  $telefono = $this->input->post("telefono"); 
  $this->email->set_newline("\r\n");
  $this->email->from($email, $nombres);
  $this->email->subject("Nueva Consulta !");
  $this->email->message('<p>'.$mensaje.,'<strong>'.$telefono.'</strong>''</p>');
  $this->email->to('[email protected]');
  if($this->email->send(FALSE)){ 
    echo json_encode("success");
  }else {
    echo json_encode("error");
  }
}
    
asked by Patricia Andres Laureano 24.08.2018 в 19:28
source

1 answer

0

I have used this library and it works perfectly just to adapt it to your needs.

$this->load->library("email");

$configGmail = array(
    'protocol'  => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com',
    'smtp_port' => 465,
    'smtp_user' => 'correo',
    'smtp_pass' => 'password',
    'mailtype'  => 'html',
    'charset'   => 'utf-8',
    'newline'   => "\r\n"
);

$this->email->initialize($configGmail);

$this->email->from('correo_quien_envia');
$this->email->bcc($email_destinatario);

ob_start();
include(APPPATH.'libraries/info.php');
$HTML = ob_get_clean();

$this->email->subject('Mensaje');
$this->email->message($HTML);
$this->email->send();
    
answered by 24.08.2018 в 19:32