0

I am trying to send an email in CodeIgniter 4 and I can't understand what am I doing wrong. Here is my code.

            $post_params = $this->request->getPost();

            $post_params = $this->db->escape($post_params);
            
            $config['mailType'] = 'html';

            // send mail to company
            $send_email = \Config\Services::email();

            $send_email->clear();

            $send_email->initialize($config);

            $send_email->setFrom('noreply@yourjob.am', 'YourJob.am | Աշխատանքային հայտարարությունների հարթակ');
            $send_email->setTo($post_params['mail']);

            $send_email->setSubject($post_params['subject']);
            $email_html = $post_params['message'];
            $send_email->setMessage($email_html);

            $send_email->send();

When I am checking errors there is no errors and in console it says "Email successfully sent"

            if ($send_email->send())
            {
                echo 'Email successfully sent';
            }
            else
            {
                $data = $send_email->printDebugger(['headers']);
                print_r($data);
            }

I also have tried regular php mail() function but no results.

Anna
  • 1
  • 2
  • What have you tried to resolve the problem? Where are you stuck? Is there anything written to your server's error log? Can you use a higher error reporting level to see more details? – Nico Haase Aug 11 '21 at 08:52
  • @Nico Haase it gives me no errors but when I am checking my email I don't get anything. – Anna Aug 11 '21 at 08:53
  • Then you should start debugging the code. Unless you share more details, it's nearly impossible to provide help – Nico Haase Aug 11 '21 at 09:10
  • 1
    Check https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail, it has a lot of possible reasons why the email might get rejected on the receiving end. Are you sending the mail via SMTP, and if so, does the `From` address you specified, match that account? – CBroe Aug 11 '21 at 09:17
  • 1
    Also consider the possibility that the code works fine and the email gets sent, but it is the receiving mail server that refuses to receive the email. It is a very common misconception that emails that are sent are always received. – KIKO Software Aug 11 '21 at 09:18
  • You can check sendmail installed on your local/server from where you are sending email – PHP Geek Aug 12 '21 at 04:20

0 Answers0