#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    8
    Rep Power
    0

    Sending SMS via PHP


    I have a website where visitors can enter a phone number to receive text alerts of events. I have it set up so the visitor can choose his provider from a dropdown of six known providers and this information is stored with the inputted number in a MySQL database as 1111111111@txt.att.net for example. I'm noticing in testing that I only receive about half the alerts on my phone hosted by Sprint. Is this a Sprint issue or something in my code?

    Code:
    $smsarray=array();
    
    $query="select * from `profiles` where `sms` !=''"; // looking for people in the db who have subscribed to text alerts
    $result=$db->query($query);
    for ($i=0; $i<$result->num_rows; $i++) {
    $row=$result->fetch_assoc();
    $smsarray[$i]=$row['sms'];
    }
    
    if ($park=="Mel Hamel Park") {
    $park="Hamel";
    } else {
    $park="Crabb";
    }
    
    $smsbody="I'm unable to make it on $day.\n";
    $smsbody.="$signedup signed up: ";
    
    $smsbody.="$hamel at Hamel, ";
    $smsbody.="$crabb at Crabb\n";
    $smsbody.="http://www.pcvball.com";
    
    $smsheader="From:my website <noreply@mydomaincom>"; 
    
    for ($i=0; $i<count($smsarray); $i++) {
    mail($smsarray[$i],$subject,$smsbody,$smsheader);
    } // I've also tried this as a foreach() loop with same results
    I'm wondering if the use of HTML tags (\n) might be the culprit or perhaps using <br> instead of \n would make a difference - dunno'.

    Thanks in advance -
    sleepydad
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    Newline (\n) isn't an HTML tag. And no, that isn't the problem. I wonder if adding sendmail -f flag would help:
    PHP Code:
    mail($smsarray[$i], $subject$smsbody$smsheader'-fnoreply@mydomain.com'); 
    I have a PHP script that sends me messages @messaging.sprintpcs.com, using mail() with a From: header and the -f sendmail flag, and I don't have any issues receiving the messages.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    8
    Rep Power
    0

    @mod_speling


    Thank you for your reply. I've never heard of using this. I've used mail() many times for email, but never for sms. I looked up sendmail after I read your reply, and what I read seems to suggest using it as a fifth parameter which is what I think you say you do. Also, I'm noticing in the reading that I've done that the online examples have a space between the '-f' and the the address. Your reply does not. What's the proper syntax?

    EDIT: I'm re-reading your post, and realizing that you clearly answered my question regarding the 5th parameter in your reply. Also, I'm noticing as I read more about this online that the examples that I'm seeing do NOT have the space between the -f and the address. I'm guessing the one that I did see with a space was a typo.
    Last edited by sleepydad; August 23rd, 2013 at 01:35 PM. Reason: Enlightenment

IMN logo majestic logo threadwatch logo seochat tools logo