For several months I used a simple PHP script embedded in a PHP file saved within an includes folder on one of my non-HTTPS sites. Here is the PHP script:
<?php
$to = "+1XXX650XXXX@vtext.com"; // my cell #
$from = "myEmail@myWebsite.com";
$message = "New Text Message ...";
$headers = "From: $from\n";
mail($to, '', $message, $headers);
?>
This worked perfectly for nearly a year and now, for some reason the script no longer sends texts. Initially I thought either Verizon or Apple were blocking these texts because their bots were viewing them as SPAM. I had Verizon check and they said it was not them blocking these texts, if anyone really was. Same with Apple.
In all of this drama, I learned that the email address had to be associated with the website being used from the POST request. For many months I just used my normal email address and had no problem. So via my cPanel, I set up an email address tied directly to the test website, verified that the email actually worked and yet, I still cannot get the script to function as it once did. I also allowed my web host 24hr to update all changes thinking this was the cause. Wrong.
If my text messaging method never worked at all that would be one thing, but it worked perfectly for months on end. And now, zip, nada.
For the sake of clarity, these texts were to be used as alerts for a water association that I have donated my time/money creating water level sensors for each of their water tanks. If the water level were to fall below 8ft they wanted to get text alerts.
There must be some logical explanation for this, but I have no idea what that may be. If anyone can shed some light on this I would be very grateful. Perhaps someone could test the script on their own?
I mean, thereâs not really a âscriptâ here. Thereâs a single mail command. Presumably, thatâs failing. Is your mail command returning true or false?
The water level project is built into an Arduino microcontroller board. When water levels drop, the ultrasonic sensor calculates the depth and from that a text is sent via the POST request to the website PHP file only if the water level has fallen below 8ft.
I looked into the error logs (2) of the website used and the last entries were from 2021, so these logs are apparently not where I can view the Mail Command results.
if (mail($to, '', $message, $headers))
{
echo "Text was sent successfully!";
} else {
echo "Text FAILED to be sent!";
}
and here is the result as seen on the webpage being used:
Shock! Now at 1045H a text message just arrived!!!
The code has been running sine 1040, texts are sent at 60 sec intervals ⌠I have no idea what is going on with this.
I often read that the standard PHP mail() function is not very good, and that something like PHPMailer can be more reliable. I donât recall the details, in terms of how that reliability improvement manifests itself.
One thing you might want to narrow down is to make sure that your PHP code is actually executing every time your Arduino calls it - write something to a log file each time it runs. Also remember that just because the mail arrives at your SMTP server, that doesnât mean itâs actually gone anywhere else. A true response just means that itâs made it to the server, as I understand it.
This problem is driving me nuts. For months on end I could send texts anytime to anyone using my simple PHP file. And then - nothing - for seemingly no reason. The code either in my Arduino sketch or the PHP file was not altered in any way.
And, now, after many test changes, I receive very sporadicly spaced text messages. Iâm no expert at any of this, but it now seems that I will have to use a much more reliable method to send these alert texts.
It was suggested to me that I should avoid using my website method and try using a SMS service. I did look at Twillio and IFTTT, but the learning curve will be very time consuming. I would rather spend a few more days trying to learn why my method no longer works than go down another unknown path that may/may not solve my problem.
I made some drastic changes to my PHP file - I exchanged my numeric cell number for Xâs and was shocked to see âText was successfully sent!â. At least I now know that that verification method is non-reliant.
I did find some good into on PHPMailer that you suggested. This article appears to be very informative. I will spend some time ingesting a few more PHPMailer articles. These are focused on email, so I will have to be able to tweak it for sending texts. It never ends.
The mail() function only reports whether it was able to send the message to the SMTP server - what happens to it after that is all in the hands of the server, and then on from there. If the SMTP server tries to send the email and gets an error response back from the destination server (in this case the server for vtext.com) it would probably send that response back to you. Some mail servers donât send out âinvalid addressâ errors because it helps spammers to figure out valid email addresses.
In your example, though, that might rely on your SMS service sending feedback like that - it might choose to just put it in some kind of log that you can examine on their server somehow. You can imagine that some of these text services are designed to send bulk text messages, so getting an individual email back every time one fails could be very annoying. On that matter, does the SMS service provide any logging that might help show whether the emails are being received and why theyâre not being sent?