SMTP mail through PHP returns false

Post your questions about Web Server usage and Apache + PHP + MySQL/SQLite web applications.
Post Reply
iainhunter
New here
Posts: 5
Joined: Wed Sep 06, 2017 8:06 am

SMTP mail through PHP returns false

Post by iainhunter »

Following a recent update of QNAP, my PHP code is failing on sending mail for a "Reset Password" option of my website. I've worked through many forums and attempts of what was suggested there with no luck. It just confirmed that what I had attempted was correct. Here is my php.info related to email:
[mail function]
SMTP = localhost
smtp_port = 25
sendmail_path = /usr/sbin/sendmail -t -i
mail.log = /usr/mail.log

Here is my PHP code for sending the email:
$status = mail($userExists["email"], "Password Reset", $mailbody);
The status comes across as "false"

I've checked $userExists["email"] and $mailbody and those are what they should be.

I don't know if something changed with the recent update of QNAP, but nothing changed in my website code, so I'm at a loss of what the problem could be.
User avatar
dolbyman
Guru
Posts: 35243
Joined: Sat Feb 12, 2011 2:11 am
Location: Vancouver BC , Canada

Re: SMTP mail through PHP returns false

Post by dolbyman »

is sendmail in the folder specified?
iainhunter
New here
Posts: 5
Joined: Wed Sep 06, 2017 8:06 am

Re: SMTP mail through PHP returns false

Post by iainhunter »

Yes. Here is the output from Putty (ssh)

[/] # find . -name sendmail
./usr/sbin/sendmail
iainhunter
New here
Posts: 5
Joined: Wed Sep 06, 2017 8:06 am

Re: SMTP mail through PHP returns false

Post by iainhunter »

I got it figured out. False was being returned due to XOAuth2 issues. When I switched my notification server to Yahoo and set "Allow apps to use less secure...", php started returning true for $status.

However, no emails were coming through. From there, I thought it may be the format of the message, so removed the parameters -t -i

Still no luck, but when I put -t back in and added this to my php:
$headers = 'From: example@example.com';
$status = mail($userExists["email"], "Password Reset", $mailbody, $headers);

everything started working.
Post Reply

Return to “Web Server & Applications (Apache + PHP + MySQL / SQLite)”