Jump to content

Reading contents from file but substitute variable wth value


rei

Recommended Posts

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.