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