Jump to content

Archived

This topic is now archived and is closed to further replies.

soapergem

SMS messaging using mail()

Recommended Posts

I've seen myriad PHP classes available on the web that allow people to send text messages to cell phones using HTTP gateways. That, however, is not what I am interested in. From what I've seen, all HTTP gateways charge money to use their services (correct me if I'm wrong). Also, that method is kind of "lazy" since it simply sends a set of POST vars to another server that will then have to do something with them. Why do that when you can use built-in PHP functions to do it yourself? (Again, correct me if I'm being presumptuous about PHP's abilities.) Anyways, I've been doing some testing sending out text messages using the mail() function, and while these tests have been successful, I can really only say that they're partially successful.

I often end up with a bunch of gibberish at the beginning. Here's one example. I used the following PHP code to try and send a test message to a friend of mine, Andrew. I've pretty obviously changed his phone number to protect the innocent. Here's the code:
[code]$to_addr = '<123456789@vtext.com>';

$subject  = 'Hey Andrew';

$message  = "Hey Andrew. So, um, I'm testing this.\r\n";
$message .= "Does it work?\r\n";
$message .= "The following letters should all be on different lines:\r\n";
$message .= "a\r\n";
$message .= "b\r\n";
$message .= "c\r\n";

$headers  = "From:<me@my.address.com>\r\n";
$headers .= "Content-Type:text/plain;charset=iso-8859-1\r\n";

mail($to_addr, $subject, $message, $headers);[/code]
But, much to my dismay, this code produced the following message on his phone:
[code]Fr:SRS0=hGuo=6D
=perfora.net=cg
i-mailer-bounces
-1048
(Hey Andrew)
Hey. So, um, I'm
testing this. Does it work?
The following
letters should all
be on different lines:[/code]
I think the reason the last three lines were truncated has to do with the character limit, although I'm not positive on that. So here's my question to pose to all of you intellectual giants: how do I get rid of the gibberish? What am I doing wrong? I feel like I'm so close, since the messages are successfully delivered, but I just can't seem to shake that random gibberish that appears. I've tried a couple of variations on the $headers, too. Any help is appreciated!

Share this post


Link to post
Share on other sites
This is just a guess, so don't strap me down and flog me to within an inch of my life if i'm wrong (i'd only enjoy it if you did)...

Won't the "gibberish" on the front end of the delivered message be appended by the server it passes through before delivery to the phone? If this gibberish is not in your ocde, it must be appended somewhere else along the route.

Share this post


Link to post
Share on other sites
[!--quoteo(post=364330:date=Apr 13 2006, 03:50 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 13 2006, 03:50 AM) [snapback]364330[/snapback][/div][div class=\'quotemain\'][!--quotec--]Won't the "gibberish" on the front end of the delivered message be appended by the server it passes through before delivery to the phone?[/quote]
Well, then my question is this: is there some way to prevent that?

Share this post


Link to post
Share on other sites
Best guess, it COULD be caused by an extra newline somewhere in the email headers. I'd try emailing it to myself to see if it's on your end or theirs.

Share this post


Link to post
Share on other sites
I was able to figure it out. Basically, SMS messaging [i]always[/i] completely ignores whatever "additional headers" you pass in to it. However, what it's really looking for is any additional [i]parameters[/i], which I wasn't even defining. The mail function is defined as follows:

[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--][!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]bool[!--colorc--][/span][!--/colorc--] [!--coloro:#0000FF--][span style=\"color:#0000FF\"][!--/coloro--]mail[!--colorc--][/span][!--/colorc--] ( [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] [b]to[/b], [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] [b]subject[/b], [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] [b]message[/b] [, [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] [b]additional_headers[/b] [, [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] [b]additional_parameters[/b]]] )[!--sizec--][/span][!--/sizec--]

And the additional parameter we need to add is precisely this:
[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]'-fme@my.address.com'[!--colorc--][/span][!--/colorc--]

For some reason, I think it's important that you leave no space between the [!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]-f[!--colorc--][/span][!--/colorc--] and your e-mail address. Not sure why, but I think it is. Anyways, that worked. To summarize, this is the code I am now using (with no problems):

[code]mail($to_addr, $subj, $message, NULL, '-fme@my.address.com');[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.