Announcement

Collapse
No announcement yet.

Reading from a file to sendmail

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading from a file to sendmail

    Hi,

    I would like to send a message when someone completes my form. I would also like the message to be read from a file I have on my server. In this file I want to put some personalization. For example, I'd like the message to read...

    PHP Code:
    Hello <? echo "$username"?>,
    Here is what I have so far:

    $fd = fopen ($mailnew, "r");
    $msg= fread ($fd, filesize ($mailnew));
    fclose ($fd);


    Then for my mail command I'm using:

    PHP Code:
    mail($to$subject$msg$mailheaders); 
    It sends the email but it doesn't replace the username...instead it sends the message just like it is in the file...
    PHP Code:
    Hello <? echo "$username"?>,
    How can I replace my variables in the file and have them sent out in the email message?

    Any ideas would be appreciated!!

    Tim
    Last edited by Tim Mousel; Tue 12 Jun '01, 10:13pm.
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available

  • #2
    [template file]
    Hello $username,

    yadda yadda yadda

    signed,
    $adminstrator
    [/template file]

    PHP Code:
    $fd fopen ($mailnew"r"); 
    $msgfread ($fdfilesize ($mailnew)); 
    fclose ($fd); 

    str_replace("\$username"$username$msg);
    str_replace("\$adminstrator"$adminstrator$msg);

    mail($to$subject$msg$mailheaders); 
    There is prolly a better way to do this though.

    Comment


    • #3
      Hi,

      Thanks for the help. For some reason that doesn't work. I would think it would but it still sends the message as:

      PHP Code:
      Hello $username... 
      Any other ideas??

      Thanks,

      Tim
      Five Star Review Script - Add reviews to your website!
      Mixed Martial Arts - Houston MMA Training
      Women's Self-Defense - Courses and DVDs available

      Comment


      • #4
        I'm an idiot

        I think you need to re-assign the string to $msg.
        PHP Code:
        $fd fopen ($mailnew"r"); 
        $msgfread ($fdfilesize ($mailnew)); 
        fclose ($fd); 

        $msg str_replace("\$username"$username$msg);
        $msg str_replace("\$adminstrator"$adminstrator$msg);

        mail($to$subject$msg$mailheaders); 

        Comment


        • #5
          That worked perfectly! Thanks Max!
          Five Star Review Script - Add reviews to your website!
          Mixed Martial Arts - Houston MMA Training
          Women's Self-Defense - Courses and DVDs available

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X