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 Link to comment https://forums.phpfreaks.com/topic/147915-reading-contents-from-file-but-substitute-variable-wth-value/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/147915-reading-contents-from-file-but-substitute-variable-wth-value/#findComment-776336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.