why is my attempt to send the email unsuccessful, I can't see the error, all I get is the http status code 303 See More
In my opinion, what I'm doing is in accordance with the official documentation https://codeigniter.com/userguide3/libraries/email.html
the result i expect is an email sent
Can anyone help me? , How can I solve this?
config/email.php
$config['settings'] = array(
'smtp_host' => 'smtp.mailtrap.io',
'smtp_port' => '2525',
'smtp_user' => '9cf16dcde1asdasde5f8',
'smtp_pass' => '079205e1asdasd26bf43',
'from_email' => 'no-reply@test.com',
'from_name' => 'Test',
'protocol' => 'smtp',
'smtp_crypto' => 'tls',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n",
'crlf' => "\r\n",
);
libraries/Ah_Email.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Ah_Email {
public function __construct()
{
$CI =& get_instance();
$CI->load->config('email', true);
$this->configs = $CI->config->config['email'];
$CI->load->library('email');
$this->email = $CI->email;
}
public function send($email_to, $subject, $template, $template_vars = array(), $settings = array())
{
$settings = array_merge(
$this->configs['settings'],
$settings
);
$this->email->initialize($settings);
$this->email->from($settings['from_email'], $settings['from_name']);
if (isset($settings['send_email']) && $settings['send_email']) {
$this->email->to($email_to);
}
$CI =& get_instance();
$this->email->subject($subject);
$this->email->message($CI->load->view('emails/' . $template, $template_vars, true));
$res = $this->email->send();
return $res;
}
}
My Controller
public function SendMail() {
$this->load->library('ah_email', 'ah_email');
$send = $this->ah_email->send('receiver@gmail.com', 'Informasi Kode OTP Akun Kamu', 'example', array(
'username' => 'Ndo Malau',
'message' => 'Hello World',
'mailtype' => 'text',
));
if($send) {
$result = redirect(base_url('Systems/Users/index/'), $this->session->set_flashdata('succ_msg', 'success, email has been sending!'));
} else {
$result = redirect(base_url('Systems/Users/index/'), $this->session->set_flashdata('err_msg', 'failed, error while email sending'));
}
return $result;
}