Search code examples
phpcodeigniter-4

Cannot send email by email class in Codeigniter


I am using codeigniter 4 to create my website. At this moment, I am trying to implement a function which sends email to the users! However, I got this message... Is there any solution to solve it? Here is my code

This is the error... The error message is "Unable to send email using SMTP. Your server might not be configured to send mail using this method"

$to = "[email protected]";

        $from = '[email protected]';
        $name = 'xxx';
        $subject = "Verification Code";
        $message = "<p> This is your verification code: 123456 </p>";

        $email->setFrom($from, $name);
        $email->setTo($to);
        $email->setSubject($subject);
        $email->setMessage($message);
        if($email->send()){
            echo "Please check your email";
        }else{
            $data = $email->printDebugger(["header"]);
            print_r($data);

        }

Solution

  • I have solved the problem already. It's because my server does not permit outgoing traffic to the Internet so I need to use specific host name instead of using my email address!