SMS Sender Help

Discussion in 'PHP' started by rfizzle, Apr 10, 2009.

  1. #1
    Ok, I am a total noob at PHP. This is like my first go editing it. I have this to send sms messages to phones:

    
    <?php
    
    
    $mobileNumber = $_POST['mobileNumber'];
    $message = $_POST['message'];
    $count = $_POST['count'];
    $provider = $_POST['provider'];
    
    for ($i = 0; $i < $count; $i++) {
     	$headers = "From: info@security-hackers.org \r\n";
    	$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
    	$headers .= "MIME-Version: 1.0 ";
    	$subject = "Sub";
    	$body = $message;
    	$email = $mobileNumber . "@" . $provider;
    	if (mail($email, $subject, $body, $headers)) {
    		echo "You have sent <b>$count</b> SMS messages to $mobileNumber";
     	} else {
      		exit(0);
      	}
    }
    
    
    ?>
    
    Code (markup):
    That one works and sends to any number.
    I want to have it to where I can block it from sending it to a few numbers. I tried to do this but it didn't work.

    
    <?php
    
    
    $mobileNumber = $_POST['mobileNumber'];
    $message = $_POST['message'];
    $count = $_POST['count'];
    $provider = $_POST['provider'];
    
    for ($i = 0; $i < $count; $i++) {
     	$headers = "From: info@security-hackers.org \r\n";
    	$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
    	$headers .= "MIME-Version: 1.0 ";
    	$subject = "Sub";
    	$body = $message;
    	$email = $mobileNumber . "@" . $provider;
    	if ($mobileNumber = '1234567890') {
            echo "You cannot send to this number." 
            exit(0); }
    
           elseif(mail($email, $subject, $body, $headers)) {
    		echo "You have sent <b>$count</b> SMS messages to $mobileNumber";
     	} else {
      		exit(0);
      	}
    }
    
    
    ?>
    
    Code (markup):
    What I am trying to do is get it to send to any number but a few ones that I do not want people to send to. Anyone got any Ideas on what I am doing wrong?
     
    rfizzle, Apr 10, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change:

    if ($mobileNumber = '1234567890')
    Code (markup):
    to
    if ($mobileNumber == '1234567890')
    Code (markup):
    One equal sign for assignment, two for comparison. The way you have it, it sets the value of $mobileNumber to '1234567890', and then checks whether the entire expression evaluates as true, so it is probably blocking all numbers from working.
     
    SmallPotatoes, Apr 10, 2009 IP
  3. BlackhatVault

    BlackhatVault Banned

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you want to send SMS via PHP, don't you need a SMS gateway? If you got one, is it expensive? I can't see how your script can send something via any gateways..
     
    BlackhatVault, Apr 10, 2009 IP
  4. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #4
    should be
    if ($mobileNumber == '1234567890') {
     
    crivion, Apr 10, 2009 IP
  5. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No you don't necessarily need a sms gateway you can use most provider's mms address or sms address like sending a sms through email thats all.
     
    atlantaazfinest, Apr 10, 2009 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    In receiver-pays countries (like USA), mobile phone companies often provide free email gateways for SMS.
     
    SmallPotatoes, Apr 10, 2009 IP
  7. rfizzle

    rfizzle Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok This works fine, thank you guys.
    
    if ($mobileNumber == '1234567890') {
    		echo "You cannot send to this number." ; }
    	elseif (mail($email, $subject, $body, $headers)) {
    		echo "You have sent <b>$count</b> SMS messages to $mobileNumber";
     	} else {
      		exit(0);
      	}
    }
    
    Code (markup):
    But when I try to add multiple phone numbers that cannot be sent to, the script doesn't work.

    
    if ($mobileNumber == '1234567890' , '11234567890' , '2134375876' ) {
    		echo "You cannot send to this number." ; }
    	elseif (mail($email, $subject, $body, $headers)) {
    		echo "You have sent <b>$count</b> SMS messages to $mobileNumber";
     	} else {
      		exit(0);
      	}
    }
    Code (markup):
    thank you
     
    rfizzle, Apr 10, 2009 IP
  8. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    like this
    
    if (($mobileNumber == '1234567890') OR ($mobileNumber == '1234567890') OR ($mobileNumber == '1234567890')) {
    		echo "You cannot send to this number." ; }
    	elseif (mail($email, $subject, $body, $headers)) {
    		echo "You have sent <b>$count</b> SMS messages to $mobileNumber";
     	} else {
      		exit(0);
      	}
    }
    
    PHP:
     
    atlantaazfinest, Apr 10, 2009 IP
  9. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    or use this

    
    $bannednum = array("1234567890", "12234567890", "12434567890", "1235567890");
    if (in_array($mobileNumber, $bannednum)) {
            echo "You cannot send to this number." ; }
        elseif (mail($email, $subject, $body, $headers)) {
            echo "You have sent <b>$count</b> SMS messages to $mobileNumber";
        } else {
          exit(0);
        }
    }
    
    PHP:
     
    atlantaazfinest, Apr 10, 2009 IP