rei Posted March 4, 2009 Share Posted March 4, 2009 I am trying to write a PHP application where an automatic response is sent out after form is posted. The contents of the email was to be read from a file, but I would like to exchange the variable in the file to the actual value of it. For example, there is a <form> and my user posted his name as "Andy". I would like my automatic response email to be appear like the following where the name is the value which the user posted. ----------------------- Dear Andy, Thank you for posting. We will contact you soon. ----------------------- However i just get the following result: ??? ----------------------- Dear $name, Thank you for posting. We will contact you soon. ----------------------- Could anyone tells me what's wrong with my code? My function looks like this: PHP Program // $inc = the file contents to be wrote in the email (data.txt) function Send_Notification($mail_to, $mail_cc, $name, $inc){ $mail_from = MAILFROM; $mail_subject = SUBJECT; $fp = fopen($inc, "r"); while(!feof($fp)){ $buffer .= fgets($fp); } $headers = "From: $mail_from"; $headers.= "Bcc: $mail_from"; $body .= $buffer; if(!mb_send_mail($mail_to, $mail_subject, $body,$headers)){ return false; } } data.txt Dear $name, Thank you for posting. We will contact you soon. Thank you Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 4, 2009 Share Posted March 4, 2009 my guess is it has something to do with single vs double quotes. <?php $name = "Andy"; echo "$name"; // prints: Andy echo '$name'; // prints: $name ?> 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.