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 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form mail with image attachment problem

    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.";
    }
    }
    ?>

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    //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);


    ?>


  •  

    Posting Permissions

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