SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Can I open a file and mail it?

    I have written a class that receives form data, scrubs it and emails the data and inserts the data into a db.

    I was hoping to be able to keep the email template files independent of the class in true OOP fashion, but I am having a hard time accomplishing what I am trying to do.

    I want to open a template file, echo out the scrubbed form data at specified places, and then mail it. Right now, all the code does is append the file contents to the top of the success page and emails the user a number, which I am assuming is the file size.

    Here's the code I have so far:
    PHP Code:
        /* this method opens the file */
        
    function readFile $file )
            {
             
    $fp fopen $file'r+' );
            }
            
        
    /* return value of readFile() */
        
    function getFile $file )
         {
           return 
    readFile $file );
          }
        
        
    /* in sendMail() method, I have this code: */
        
    function mailForm ()
        {
          
    $dealers = array (.....)
                        
          foreach ( 
    $dealers as $dealer ) {
             if ( 
    in_array $_POST[STATE], $dealer['states'] ) ) {
                
    $to $dealer['email'];
             } else {
             
    $to "me@myEmail.com";                 
             }
           }
                
           
    $mail = new phpmailer;
                
           
    $mail->ClearAddresses();
           
    $mail->ClearCCs();
           
    $mail->FromName $_POST[FNAME] . " " $_POST[LNAME];
           
    $mail->From $_POST[EMAIL];
           
    $mail->AddAddress $to );
           
    $mail->AddAddress $_POST[EMAIL] );
           
    $mail->AddCC TR_EMAIL );
           
    $mail->AddReplyTo $_POST[EMAIL] );
           
    $mail->Subject "Yuppie Wagon Contact Form";
                
            if ( isset ( 
    $_POST[ISHTML] ) && $_POST[ISHTML] == 'false' ) {
               
    $mail->Body $this->getFile TEXT_TPL );
             } else {
               
    $mail->IsHtml true );
               
    $mail->Body $this->getFile HTML_TPL );
             }
                
             if ( 
    $mail->send() ) {
               
    $this->success true;
             }
        } 
    //end method mailForm() 
    TEXT_TPL and HTML_TPL are constants that equal the relative URL to the pages I am trying to include in the email as the body of the email.

    Can anyone point me in the right direction, or is what I am trying to do not possible?
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."


  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't think you want to be using readfile(). That dumps the file directly to the output buffer. Take a look at http://us2.php.net/manual/en/function.fread.php for reading the file contents into a variable to use.

  3. #3
    I want my 4th arrow! garlinto's Avatar
    Join Date
    Jun 2002
    Location
    Riding the electron wave
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. fread() worked much better. But what I now need is to parse the file to echo the variables within the text (i.e., echo out the embedded $_POST[' '] vars so the user can see the input he/she entered into the form).

    Any suggestions?
    Ducharme's Axiom: "If you view your problem closely
    enough, you will recognize yourself as part of the problem."


  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    In your template, put placeholders in where you want to replace the text in the mail with the posted text, like {NAME}, {EMAIL}, etc. Then use eregi_replace(), str_replace(), or any of the regex functions to do a simple replace on the variable (e.g. eregi_replace("{NAME}",$_POST['name'],$template))


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
  •