Jump to content

MailScripts OH YAY!!


Sravan

Recommended Posts

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 require_once("java/Java.inc");
      
  $filename = $_FILES['file']['name'];
  $path = $_FILES['file']['tmp_name'];
  $to = "[email protected]"
  $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:

<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

Link to comment
https://forums.phpfreaks.com/topic/204920-mailscripts-oh-yay/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.