0

I'm currently having issues with my mail. It is sending just fine, I get an attachment with a name and a size but it can't be opened. Also I already tried PHPMailer and the SMTP doesn't work on my server so please don't advise me to get on it :)

Sorry about the french variables names and error message but I don't think it would be useful. I can translate if you need it of course.

Here is the piece of code that takes care of my attachment.

    if(isset($_FILES["fichier"]) &&  $_FILES['fichier']['name'] != ""){
        $nom_fichier = $_FILES['fichier']['name'];
        $source = $_FILES['fichier']['tmp_name'];
        $type_fichier = $_FILES['fichier']['type'];
        $taille_fichier = $_FILES['fichier']['size'];

        if($nom_fichier != ".htaccess"){
             if($type_fichier == "image/jpeg" 
                || $type_fichier == "image/pjpeg" 
                || $type_fichier == "application/pdf"){

                if ($taille_fichier <= 2097152) {
                    $tabRemplacement = array("é"=>"e", "è"=>"e", "à"=>"a");

                    echo("Nom du fichier : ".$nom_fichier."<br/>");
                    echo("Nom du fichier temporaire : ".$source."<br/>");
                    echo("Type du fichier : ".$type_fichier."<br/>");
                    echo("Taille du fichier : ".$taille_fichier."<br/>");

                    $handle = fopen($source, 'r');
                    $content = fread($handle, $taille_fichier);
                    $encoded_content = chunk_split(base64_encode($content));
                    $f = fclose($handle);

                    $email_message .= $passage_ligne . "--" . $boundary . $passage_ligne;
                    $email_message .= 'Content-type:'.$type_fichier.';name='.$nom_fichier."\n";
                    $email_message .= 'Content-transfer-encoding:base64'."\n";
                    $email_message .= $encoded_content."\n";
                    //$email_message .= $passage_ligne . "--" . $boundary . "--" . $passage_ligne;
                }else{
//Error message
                    $email_message .= $passage_ligne ."L'utilisateur a tenté de vous envoyer une pièce jointe mais celle ci était superieure à 2Mo.". $passage_ligne;
                }
            }else{
//Error message
                $email_message .= $passage_ligne ."L'utilisateur a tenté de vous envoyer une pièce jointe mais elle n'était pas au bon format.". $passage_ligne;
            }
        }else{
//Error message
            $email_message .= $passage_ligne ."L'utilisateur a tenté de vous envoyer une pièce jointe .htaccess.". $passage_ligne;
        }
    }
Malane
  • 15
  • 4
  • Clearly mario is not reading the post and just marking everything duplicate because i already read this post before and it didnt help me... – Malane Oct 18 '15 at 08:44

1 Answers1

0

You should have two newlines before the content. The mail message should look like this:

Content-Type: multipart/alternative; boundary=foobar

--foobar
Content-Type: …
Content-Transfer-Encoding: …

base64data…
--foobar--

You are missing the white line between the Content-Transfer-Encoding and your data.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175