SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member slokey.com's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    new to PHP, need a file attached in an email

    I'm brand new to PHP, as of today, and I found this code that allows me to submit a form to my email.....but the catch is, it won't send the attached file. The question is what code do I need for the PHP page and what do I need for the FORM in order to make this happen. Thanks...

  2. #2
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class SameSender{
    ................
        function 
    attachedSendMailTo$mail ){
            
    $un strtoupper(uniqid(time()));
            
            
    $head  "From: ".$this->from."<".$this->re.">\r\n";
            
    $head .= "To: ".$mail."\r\n";
            
    $head .= "Subject: ".$this->title."\r\n";
            
    $head .= "X-Mailer: PHPMail Tool\r\n";
            
    $head .= "Reply-To: ".$this->re."\r\n";
            
    $head .= "Mime-Version: 1.0\r\n";
            
    $head .= "Content-Type:multipart/mixed;";
            
    $head .= "boundary=\"----------".$un."\"\n\n";
            
            if ( (
    $body =& $this->createAttachedBody$un )) == null)
                return;

            if (!@
    mail($mail$this->title$body$head)){
                
    $this->errorEventCode "cant_send_mail";
            }
        }
        
        function &
    createAttachedBody$un ){
            static 
    $body;
            
            if (!isset( 
    $body )){
                if (!
    file_exists$this->attachFileName )){
                    
    $this->errorCode "not_set_file"; return null;
                }
                
                if ( ! 
    $f = @fopen($this->attachFileName,"rb") ){
                    
    $this->errorCode "cant_read_file"; return null;
                }
            
                
    $body  "------------".$un."\nContent-Type:text/html;\n";
                
    $body .= "Content-Transfer-Encoding: 8bit\n\n".$this->text."\n\n";
                
    $body .= "------------".$un."\n";
                
    $body .= "Content-Type: application/octet-stream;";
                
    $body .= "name=\"".basename($this->attachRealName)."\"\n";
                
    $body .= "Content-Transfer-Encoding:base64\n";
                
    $body .= "Content-Disposition:attachment;";
                
    $body .= "filename=\"".basename($this->attachRealName)."\"\n\n";
                
    $body .= chunk_split(base64_encode(fread($f,filesize($this->attachFileName))))."\n";
            }
            
            return 
    $body;
        }

    ................
        var 
    $title;
        var 
    $text;
        var 
    $re;
        var 
    $attachRealName;
        var 
    $attachFileName;

    may be it will help to you

  3. #3
    SitePoint Member slokey.com's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks...but I'm not sure what to do with that code. Here's the code I'm using....It works great, except for the file attachment.

    <?php

    /*


    */

    $my_email = "email@youremail.com";

    /*


    */

    $continue = "/page.htm";

    /*


    */

    // This line prevents values being entered in a URL

    if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}

    // This line prevents a blank form being sent

    while(list($key,$value) = each($_POST)){if(!(empty($value))){$set=1;}$message = $message . "$key: $value\n\n";} if($set!==1){header("location: $_SERVER[HTTP_REFERER]");exit;}


    $subject = "Place Subject Here";
    $headers = "From: " . $Email . "\n" . "Return-Path: " . $Email . "\n" . "Reply-To: " . $Email . "\n";

    mail($my_email,$subject,$message,$headers);

    ?>

    there's some more, but it's just HTML

  4. #4
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sender =& new SameSender();

    $sender->from "Slokey.com";
    $sender->title "bla bla bla";
    $sender->text "hello world";
    $sender->re "your@email";
    $sender->attachRealName "here write path where file is placed in realy";
    $sender->attachFileName "here write file name, what will see receiver"

    // if you have once receiver
    $sender->attachedSendMailTo"receiver@host.ext" );

    // or if you have many receivers
    foreach( $receivers_emails as $mail ){
        
    $sender->attachedSendMailTo$mail );

    all are simple, OOP is great! 8)

    sorry, i'm not understend your html, but think, that you can join it with my small tutorial

  5. #5
    SitePoint Member slokey.com's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am still having problems, is there anywhere I can get a code that will allow me to send form information into a PHP page, along with a file attachment, and be able to receive both the information and the file attachment in an email? I know the code exists, but I am having a hard time figuring out what goes where......Any help would be much appreciated....

  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at this article by Kevin Yank. It should get you squared away pretty quickly.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web


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
  •