tags:

views:

43

answers:

2

okay, here is the code

while (!feof($text)) {
    $name = fgets($text);
    $number = fgets($text);
    $carrier = fgets($text);
    $date = fgets($text);
    $line = fgets($text);


    $content = $_POST['message']; 

    $message .= $content; 
    $message .= "\n";
    $number = $number;


    mail("[email protected]", "Event Alert", $message, "SGA"); 
    Header("Location: mailconf.php");
}

I am trying to get a message sent to a phone, I have 'message' coming in from a text area, and then I assign it to "$content" then I put "$content" into "$message" and then as you can see, in my mail line, I want the address to be the variable "number"@vtext.com I have the while loop because there are many people in these files I wish to send a message to... When I change the "[email protected]" to my email address, it sends everything fine, I just cannot seem to get it to send to a phone number, please help! thanks!

+1  A: 

You need to append the number variable and the "@vtext.com" literal string together:

mail($number . "@vtext.com", "Event Alert", $message, "SGA"); 
Kaleb Brasee
This is not his problem. `@` is an invalid character for a PHP variable, and as such it has no trouble knowing that the variable is called `$number` not `$number@...`
Doug Neiner
+1  A: 

The problem is that fgets includes the newline character as part of the return. So you are effectively sending an email to:

1234567890
@vtext.com

Which of course is invalid. Change your line that reads $number = $number to:

$number = trim($number);

And the rest of your code should function as expected, with the email being received on your phone.

Part of my original answer

I would highly recommend using a (probably paid) service to send SMS messages to phones if you need anything remotely reliable. A quick search yielded a few results:

  1. PHP/SMS Tutorial
  2. A list of 5 ways to Text for free <-- This link is dated, but might still be helpful
Doug Neiner
I had looked into that, I was just trying to find a way to do it without paying. It should work in theory, I changed the "to" line to (myphone)@vtext.com and it sent the message including $number in the message fine... really confused...
Ryan
Sorry Ryan, I missed the bug which was that `fgets` is bringing the newline character as part of your string.
Doug Neiner
awesome, thank you, that fixed the issue perfectly!
Ryan
@Ryan Glad it worked! Don't forget to click the green check next to this answer to mark it solved. You and I will both get rep points, and when you ask questions in the future a high "accept" rate is really important. Welcome to Stack Overflow!
Doug Neiner
Thanks! Question answered!
Ryan