Jump to content


Photo

SMS messaging using mail()


  • Please log in to reply
4 replies to this topic

#1 soapergem

soapergem
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 April 2006 - 08:41 AM

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:
$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);
But, much to my dismay, this code produced the following message on his phone:
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:
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!

#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 13 April 2006 - 08:50 AM

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.
wisewood: proven fact, I am both wise, and wooden.

#3 soapergem

soapergem
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 April 2006 - 03:09 PM

[!--quoteo(post=364330:date=Apr 13 2006, 03:50 AM:name=wisewood)--][div class=\'quotetop\']QUOTE(wisewood @ Apr 13 2006, 03:50 AM) View Post[/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?

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 13 April 2006 - 10:49 PM

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.


#5 soapergem

soapergem
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 April 2006 - 11:45 PM

I was able to figure it out. Basically, SMS messaging always completely ignores whatever "additional headers" you pass in to it. However, what it's really looking for is any additional parameters, 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--] to, [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] subject, [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] message [, [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] additional_headers [, [!--coloro:#009999--][span style=\"color:#009999\"][!--/coloro--]string[!--colorc--][/span][!--/colorc--] additional_parameters]] )[!--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):

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users