Jump to content

rei

Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Posts posted by rei

  1. 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

     

     

  2. is there anyway i can compare 3 or more date type column?

    let's say i have
    ------------------------------------------------
    date1  |  date2 | date3
    ------------------------------------------------
    2006-06-01 | 2006-06-15 | 2006-09-19
    ------------------------------------------------

    and my select statement returns this 3 value.

    is there any way i can write in PHP to get the earliest or the latest date?
    let's say:
    [code]
    $earliest = XXX($row[date1], $row[date2], $row[date3])  <- returns ("2006-06-01")

    $latest = XXX($row[date1], $row[date2], $row[date3])  <- returns ("2006-09-19")
    [/code]

    i tried to get these from mysql command like if possible but cant find any way to do it..
    i guess there's no function to this..
    select XXXXX(date1,date2,date3)  <--returns '2006-06-01 '
    select YYYYY(date1,date2,date3)  <--returns '2006-09-19
  3. willfitch,
    thanks for the reply
    but i still get the result as following
    [quote]
    apple1
    orange2
    lime3
    strawberry4
    newlinele5
    mango6
    [/quote]

    my code is as following:
    [code]
    <?php
    $file = file("data/file.txt");

    foreach($file as $line_number => $contents){
       if(trim($contents) == 'strawberry'){
           fputs($fp, "newline");
       }
    }
    ?>
    [/code]

    is it that fputs isnt a good idea?

    [quote author=willfitch link=topic=100146.msg394895#msg394895 date=1152589232]
    Well,

    If you are hard-coding your parameters with your if conditions, you could use file() and do a foreach() loop and loop through each line.  Once you hit the strawberry, insert your new line.
    [code=php:0]
    <?php
    $file = file('file.txt');
    foreach($file as $line_number => $content) {
        if (trim($content) == 'strawberry') {
            // do your thing here.
        }
    }
    ?>
    [/code]
    [/quote]
  4. i have a file with the contents of :
    [quote]
    apple1
    orange2
    lime3
    strawberry4
    pineapple5
    mango6
    [/quote]

    i would like to insert one newline "newline" in between "lime3" and "strawberry4"

    first i wrote my code like this:
    [code]
    <?php

    $fp = fopen("data/file.txt", "r+");

    while($buf = fgets($fp)){
        if(preg_match("/strawberry/", $buf)){
            fputs($fp, "newline\n");
        }
    }
    ?>
    [/code]
    but it ended up like this:
    [quote]
    apple1
    orange2
    lime3
    strawberry4
    newline
    e5
    mango6
    [/quote]

    so i changed my code to the following (omitting \n at the end of "newline")
    [code]
    <?php

    $fp = fopen("data/file.txt", "r+");

    while($buf = fgets($fp)){
        if(preg_match("/strawberry/", $buf)){
            fputs($fp, "newline");
        }
    }
    ?>
    [/code]

    but i got the result of
    [quote]
    apple1
    orange2
    lime3
    strawberry4
    newlinele5
    mango6
    [/quote]

    i cant seem to have a line inserted in between..
    it replaces the line after it..

    i would appreciate any help
    thanks
×
×
  • 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.