PHP SMS script no longer works

Greetings,

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?

Thank you.

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?

I don’t see a POST request there.

I am not aware of any ‘mail command’. Can you please elaborate on that?

Thank you.

The POST request is in my Arduino sketch.

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.

Thank you.

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.

Will continue searching for the correct info.

Got it! Thanks for that info.

Here is the new PHP code:

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:

text-sent-successfully

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.

Thank you for your help.

Could just be the mail server was offline or lagging… shrug

You could be correct. As of 1055 I have only received two texts. The serial monitor of the Arduino IDE shows that 16 texts have been sent.

This used to be very reliable, but that is no longer the case.

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.

1 Like

Thank you very much for your comments.

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.

I sincerely appreciate your help.

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?

Another advantage of using PHPMailer is you can set debug mode which may help track where it is going wrong.