$email->send() always returns false but the email is received |
Hey there,
so the problem is pretty much in the title, the $email->send() function always returns false, even though I receive the email without any problem on every email address (to, cc, bcc). Code sample below. I'm using the latest branch of CI4. Code: $email = Services::email(); Any idea? Thanks in advance!
To dig into your question please tell what is the he mail sending protocol (mail, sendmail, smtp) you are using?
Also if you are in Windows or Linux environment, virtual host or private server, what is PHP version, etc. I am using email sending in CI4 in my project pretty much same way you do and it works fine (CentOS7, PHP 7.4, CI4.0.2, smtp).
My mail sending protocol is SMTP. I'm on Linux (x86_x64) and my PHP version is 7.3, with the latest CI4 stable branch.
Anyway, the problem seems to be "fixed" now, even though absolutely nothing has changed. The PC was running all night, so there was no restart that could have fix something, nor the code was modified in any way. Right now, most of the time everything goes okay, but sometimes it still returns false, even though the email went through, so it's not too reliable. Could be something on my end? If so, how can I debug it properly to know what's going on? Thanks for the answers!
Thanks, this makes sense. Seems we have everything to troubleshoot your problem.
Email is sent through SMTP using sendWithSMTP() function declared in system/Email/Email.php class: https://github.com/codeigniter4/CodeIgni.../Email.php Looks that this function can return false even if email was sent successfully! Take a look at this code (comments are mine): PHP Code: $this->sendData($this->headerStr . preg_replace('/^\./m', '..$1', $this->finalBody)); So in your case email is sent to SMTP server, but server sometimes responds with some other code then only expected code 250. Here is the full list of codes, however, particular SMTP server software may implement additional codes, or have other meaning: https://en.wikipedia.org/wiki/List_of_SM...xx_Success I would suggest you to debug sendWithSMTP() function by writing $reply variable values you are getting from SMTP server to log file, and then to analyze if there are any other responses then 250 (my guess will be 252 or 251, both are good candidates based on description). If you could confirm and provide more information, we could improve this part in CI4. Looking forward to hearing from you. |
Welcome Guest, Not a member yet? Register Sign In |