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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.