Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MailScripts OH YAY!!

    So, I've been working on this PHP Mail Attachment script. I sort of figured out what's going on, and mostly copied code from all over the place:
    PHP Code:
    <?php require_once("java/Java.inc");
          
      
    $filename $_FILES['file']['name'];
      
    $path $_FILES['file']['tmp_name'];
      
    $to "me@mydomain.com"
      
    $from_mail $_POST['email'];
      
    $from_name $_POST['name'];
      
    $subject $_POST['subject']; 
      
    $message $_POST['message'];

      
    $content chunk_split(base64_encode(file_get_contents($path.$filename)));
      
    $uid md5(uniqid(time()));
      
    $name basename($file);
     
      
    $ext explode('.'$filename);
      
    $ext $ext[1];

      if(
    $ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") {
      
    $mime_type "image/jpeg";
      }
      elseif(
    $ext == "gif" || $ext == "GIF") {
      
    $mime_type "image/gif";
      }
     
      
    $header "From: ".$from_name." <".$from_mail.">\r\n";
      
    $header .= "MIME-Version: 1.0\r\n";
      
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
      
    $header .= "This is a multi-part message in MIME format.\r\n";
      
    $header .= "--".$uid."\r\n";
      
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
      
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
      
    $header .= $message."\r\n\r\n";
      
    $header .= "--".$uid."\r\n";
      
    $header .= "Content-Type: ".$mime_type."; name=\"".$filename."\"\r\n"// use different content types here
      
    $header .= "Content-Transfer-Encoding: base64\r\n";
      
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
      
    $header .= $content."\r\n\r\n";
      
    $header .= "--".$uid."--";
     
      
    mail($to$subject""$header)
    ?>
    So this script successfully emails, along with an attachment. However, the problem is the attachment is 0 bytes. Any ideas?

    I'm running this through Tomcat 6.0 (using PHP/JavaBridge) on CentOS 5, with PHP 5.3 (the latest).

    The following is the HTML Code which calls the above script:
    Code:
    <form name="contribute" action="contribute.php" method="post" enctype="multipart/form-data">
     Name/E-mail: <br /><input name="name" size="30"><br /><br />
     Subject:     <br /><input name="subject" size="30"><br /><br />
     Attachment:  <br /><input type="file" name="file" id="file" size="30"><br /><br />
     Message: <br />
     <textarea name="message" COLS=50 ROWS=10 wrap="soft"></textarea><br /><br />
      <input type="submit" value="Submit">  
    </form>
    Thanks for the help!
    Sravan

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Tough one to troubleshoot from where I'm sitting, but I have kind of another solution you may want to try out. There's an open source email library you should check out. It's called PHP Mailer and it makes the task of sending emails with attachments really easy, almost disgustingly so. It takes literally 15 minutes to install and write the code for a simple email with attachment test.

    So... you can reinvent the wheel... again... or take advantage of the hard work of others... your choice

    http://phpmailer.worxware.com/

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well the thing, is I tried playing around with that, and another mail script, but it's been giving me trouble as well. So it'll still take me sometime to get working on those.

    So if you can think of any possible solutions, or if you need me to provide other information, lemme know. I'll try the phpmailer as well.

  • #4
    New Coder
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just used phpmailer, took me sometime to get it all set. I'm still curious as to the answer for this problem, but I won't be checking the thread anymore.

    Anyone figures it out, send me a PM, please.

    Thanks!!


  •  

    Posting Permissions

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