...

View Full Version : form mail with image attachment problem



dude88
04-27-2006, 04:36 PM
Can anyone help me with this form mail with image attachment script?It doesn't upload the file.


<?php
// Check to see if the form has been posted
if (isset($_POST['SendFile']))
{
// Set the Array of acceptable FileTypes
$FileTypes=array("image/jpg", "image/gif", "image/jpeg", "image/pjpeg");
// Check to ensure the uploaded file is of correct type
if (in_array($_FILES['uploadfile1']['type'],$FileTypes) && in_array($_FILES['uploadfile2']['type'],$FileTypes) && in_array($_FILES['uploadfile3']['type'],$FileTypes))
{
// Set the upload directory

$UploadDir = 'www/directory_name';

// Move the file
move_uploaded_file($_FILES['uploadfile1']['tmp_name'], $UploadDir . $_FILES['uploadfile1']['name']);
move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $UploadDir . $_FILES['uploadfile2']['name']);
move_uploaded_file($_FILES['uploadfile3']['tmp_name'], $UploadDir . $_FILES['uploadfile3']['name']);

// Open the file and read the contents into a string

$FileName=$UploadDir.$_FILES['uploadfile1']['name'].$UploadDir.$_FILES['uploadfile2']['name'].$UploadDir.$_FILES['uploadfile3']['name'];
$FilePointer=fopen($FileName, "r");
$File=fread($FilePointer, filesize ($FileName));
fclose($FilePointer);

// Encode and chunk split the data for the e-mail

$File=chunk_split(base64_encode($File));

// Set the receiving e-mail address

$EMail="reciever@domain.com";


// Set the headers of the e-mail
$Headers="From: senderemail@domain.com\n";
$Headers.="Reply-To: senderemail@domain.com\n";
$Headers.="MIME-Version: 1.0\n";
$Headers.="Content-Type: multipart/mixed; boundary=\"MIME_BOUNDRY\"\n";
$Headers.="X-Sender: senderemail@domain.com\n";
$Headers.="X-Mailer: PHP4\n";
$Headers.="X-Priority: 3\n";
$Headers.="Return-Path: senderemail@domain.com\n";
$Headers.="This is a multi-part Contentin MIME format.\n";
// Set the Content of the e-mail
$Content="--MIME_BOUNDRY\n";
$Content.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$Content.="Content-Transfer-Encoding: quoted-printable\n";
$Content.="\n";
$Content.="".$_POST['name']." just sent you a picture.\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY\n";
$Content.="Content-Type: ".$_FILES['uploadfile1']['type']."; name=\"".$_FILES['uploadfile1']['name']."\"\n";
$Content.="Content-Type: ".$_FILES['uploadfile2']['type']."; name=\"".$_FILES['uploadfile2']['name']."\"\n";
$Content.="Content-Type: ".$_FILES['uploadfile3']['type']."; name=\"".$_FILES['uploadfile3']['name']."\"\n";
$Content.="Content-disposition: attachment\n";
$Content.="Content-Transfer-Encoding: base64\n";
$Content.="\n";
$Content.="$File\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY--\n";
// Set the Subject of the e-mail
$Subject="New Featured Advertisment";
// Send the e-mail
mail($EMail,$Subject,$Content,$Headers);
}else
{
echo "only picture files.";
}
}
?>

Aruna Attanayak
05-09-2006, 01:53 PM
//this code may help u
//this code segment will attach an image001.jpg and send
//modify your code according to this

<?
$filename='image001.jpg';
$file = fopen($filename,'rb');
$data = fread($file,filesize($filename));
fclose($file);

$data = chunk_split(base64_encode($data));

$from ="aruna@wavenet.lk";
$to="aruna@wavenet.lk";
$subject="nothing";
$date=getdate();
$mime_boundary="ZEND-12345";

$headers="From: ".$from;
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";


$email_message . "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: application/msword; \n".
" name=\"{$filename}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .
$data."\n\n" .
"--{$mime_boundary}\n";



mail($to, $subject, $email_message, $headers);


?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum