Z_Smith Posted February 9, 2011 Share Posted February 9, 2011 I have been working a a program to send text messages using php but my headers containing the "From:" part of the text message keep on returning an error. Could someone please explain what i'm doing wrong. I have attached the php script and the html page I am using as a form. <?php $from = $_POST['from']; $to = $_POST['to']; $carrier = $_POST['carrier']; $carrierFrom = $_POST['carrierFrom'] $message = stripslashes($_POST['message']); //From Function if ($carrierFrom == "verizon") {$formatted_from = $from."@vtext.com";} if ($carrierFrom == "tmobile") {$formatted_from = $from."@tomomail.net";} if ($carrierFrom == "sprint") {$formatted_from = $from."@messaging.sprintpcs.com";} if ($carrierFrom == "att") { $formatted_from = $from."@txt.att.net"; if ($carrierFrom == "gmail") { $formatted_from = $from."@gmail.com"; } //To Function if ($carrierFrom == "verizon") {$formatted_number = $to."@vtext.com";} if ($carrier == "tmobile") {$formatted_number = $to."@tomomail.net";} if ($carrier == "sprint") {$formatted_number = $to."@messaging.sprintpcs.com";} if ($carrier == "att") {$formatted_number = $to."@txt.att.net";} if ($carrier == "gmail") {$formatted_number = $to."@gmail.com";} //Send $sent = mail($formatted_number,$message,$formattedFrom) ; if($sent) {print "Your text was sent successfully"; } else {print "We encountered an error sending your text"; } ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 9, 2011 Share Posted February 9, 2011 What would the error be? Quote Link to comment Share on other sites More sharing options...
Z_Smith Posted February 9, 2011 Author Share Posted February 9, 2011 The "from:" header comes in as "anonymous". Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 9, 2011 Share Posted February 9, 2011 The From: header should typically be set to a valid address on your mail server, and if a reply-to address is needed, a Reply-to: header would be added. But at any rate, where you define the $formattedFrom variable, if you're going to use it as a header, you need to define it as below, otherwise, it isn't recognized as a header; it's just an email address in a place it doesn't belong . . . $formattedFrom = 'From: ' . $from . '[then the carrier specific string]'; Quote Link to comment Share on other sites More sharing options...
trivikrama Posted February 9, 2011 Share Posted February 9, 2011 I think you have to use if.....elseif conditions Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.