Hi;

I can't find any recent posts about this problem...

I am trying to write a script that will send a text message to a cel phone (I've been using Verion's (phonenumber@vtext.com) system. I've got the basics of it working okay, but have not figured out how to get the "From:" (or Fr🙂 to work properly (it always fills in with my server's default sendmail_from value of "me@localhost.com").

Here are the basics of the functional script.

<?
foreach ($_POST as $var=>$value) {
$$var="$value"; //echo "$var: $value<br>";
}

$messagestring="\r\n$Name\r\nPh:$Phone\r\nContactEmail:$ContactEmail\r\nRE: $Listing  $Message";

// Set the variables for the database access:
///First put the info into a table to facilitate recordkeeping
$Host = "localhost";
$User = "nevermind";
$Password = "wouldntyouliketoknow";
$DBName = "databasename";
$Link = mysql_connect ($Host, $User, $Password);
mysql_select_db($DBName);
$new_inquiry = "INSERT INTO inquiries (inq_id, Name, Phone, ContactEmail, CCRE_ID, Message, submitted) VALUES ('','$Name','$Phone','$ContactEmail','$CCRE_ID','$Message', NOW())";
$Resultnew_inquiry= mysql_query($new_inquiry, $Link);

//send to staff member's regular email too..
$success2 =mail($EMAIL,'CCRE_site',$messagestring,'FROM:$ContactEmail');   

//send as a text message to staff member's cel phone 
// ******** PROBLEM: THE headers section does not work...'FROM:$ContactEmail' ...only "me@localhost.com" appears in message ********
$success =mail($VTEXT,'CCRE_site',$messagestring,'FROM:$ContactEmail');   

//kludge/workaround: Included  $ContactEmail in $messagestring

if($success)
    {
//<!--close window without Javascript-->	    
echo "<br>Your message was sent. Thank you.<p align=\"left\"><input type=\"button\" value=\"Close this window\" onclick=\"self.close()\"></p>"; exit;} else { echo "<br>There was a problem sending your message. <br>Please try again later. Thank you.<p align=\"left\"><input type=\"button\" value=\"Close this window\" onclick=\"self.close()\"></p>";
exit;} ?>

(BTW my pages are on a Windows server and the provider refuses to upgrade from php v4.1.2)

    The proper header is

    FROM: My Name <me@you.com>\r\n

      Not to mention that single quotes won't parse variable values so:
      'FROM: $ContactEmail' literally prints:

      FROM: $ContactEmail

      whereas double quotes parse variable values, so:
      "FROM: $ContactEmail" prints:

      FROM: me@mydomain.tld

        I figured out how to put that stuff together and I think I've got it to work!

        <?
        foreach ($_POST as $var=>$value) {
        	$$var="$value"; //echo "$var: $value<br>";
        	}
        
        // Set the variables for the database access:
        $Host = "localhost";
        $User = "blah";
        $Password = "blahblah";
        $DBName = "blahblahblah";
        $Link = mysql_connect ($Host, $User, $Password);
        mysql_select_db($DBName);
        $new_inquiry = "INSERT INTO inquiries (inq_id, Name, Phone, Email, CCRE_ID, Message, submitted) VALUES ('','$Name','$Phone','$Email','$CCRE_ID','$Message', NOW())";
        $Resultnew_inquiry= mysql_query($new_inquiry, $Link);
        mysql_close($Link);
        
        $messagestring="\r\n$Name\r\nPh:$Phone\r\nRE: $Listing  $Message";
        
        $huh=ini_set('sendmail_from', $Email);
        echo "<br>DEBUG: $huh<br>"; //for some reason this shows "me@localhost.com"
        
        $header="FROM: $Name <$Email>\r\n";
        
        $success2 =mail($EMAIL,'CCRE_MSG',$messagestring,$header);   
        $success =mail($VTEXT,'CCRE_MSG',$messagestring,$header); if($success) { //<!--close window without Javascript-->
        echo "<br>Your message was sent. Thank you.<p align=\"left\"><input type=\"button\" value=\"Close this window\" onclick=\"self.close()\"></p>";
        exit;} else { echo "<br>There was a problem sending your message. <br>Please try again later. Thank you.<p align=\"left\"><input type=\"button\" value=\"Close this window\" onclick=\"self.close()\"></p>";
        exit;} ?>

        I'm not really clear on why this works, but it does! It probably needs some fine tuning.

        Thanks!

          You see $varibals cannot be red in '$from' but in this "$from" it will work.

            Variables within single quotes are literal and variables within double quotes are interpreted.

              Write a Reply...