Results 1 to 4 of 4

Thread: print string stored in txt/htm file

  1. #1
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default print string stored in txt/htm file

    Hi All,

    I am new to PHP and need help on below:

    I have one text/html file that contains string to send emails to user, now that text/html file contains php variables also. i dont know how to replace those variables with actual values stored in a variables. For Ex.

    txt file contains...
    "Dear $username,
    We have received your order..."


    now when we do
    echo $file_content

    it displays $username instead of values

    how to display actual value for this, please help on this.

    Thanks in advance

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    It would be easier to answer this if we could see your code.

    I'm assuming that your HTML file is collecting data from field inputs.

    One of the ways to send an email using this data is to have a Form method, eg method="POST" and then an action that calls the PHP emailer.

    In the PHP script you need to get the values of the various fields by $varname1=$_POST['fieldname1'];.

    To then build up another variable that would be the emailed string, using the values of the PHP variables, you can concatenate by using the ".".

    Eg $messageline1="Dear ".$varname1;
    $messageline2="Thank you for your order no. ".$varname2;

    Or $message = "Dear \t$varname1 \n
    \nThank you for your order no. :\t$varname2\n
    \n";

    However if you want the email to look similar to an HTML input page, ie logos, layout, etc., then you need to use an emailer that enables this, there are a number of PHP HTML email scripts out there, some of which are surprisingly easy to use.

  3. #3
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey Thanks for the help,

    my intension is to create mail templates only..

    I have received all my FORM variables to PHP, now variables contain values.
    I have read HTML template content by fread to a PHP variable $MailBody

    now $MailBody contains string like

    Dear $username,
    We have received your order...


    If you see above, $MailBody contains another PHP variable inside string,
    and I want to replace that variables value with $username variable that i received from FORM method

    Ex.

    $username = $_POST['username']; // value is John

    $MailBody = read_file("template.htm"); // Value is Dear $username

    echo $MailBody;

    // it prints dear $username instead of Dear John

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    You could always do this

    PHP Code:
    $username $_POST['username']; // value is John

    $MailBody read_file("template.htm"); // Value is Dear

    echo $MailBody.$username
    The other thing you could try is to build the HTML string that you put into "template.htm" like this
    Code:
    var1='"Dear".$username'
    and echo this

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •