Jump to content

Recommended Posts

Hello everybody, I made this mailscript so people can send 2 attachments and some information to my email:

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Sleutel bestelling</title>
<style type="text/css">
<!--
.tekst {
font-family: Verdana, Geneva, sans-serif;
font-size: 10px;
}
-->
</style>
<link href="css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css">
<script src="js/SpryCollapsiblePanel.js" type="text/javascript"></script>
</head>

<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   $to="duivenvoorde@breur.com";
   $subject="Sleutel/Cilinder Bestelformulier";

   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

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

    $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
    $headers .= "X-Mailer: PHP v".phpversion()."\r\n";         

   $message= '<table cellspacing="0" cellpadding="8" border="0" width="400">
            <tr>
                <td colspan="2"></td>
            </tr>
            <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fromname.'</td>
            </tr>
            <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fromemail.'</td>
              </tr>
            <td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
         </table>';

   $message = "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
   $message . "\n\n";

   foreach($_FILES as $userfile){
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      if (file_exists($tmp_name)){

         if(is_uploaded_file($tmp_name)){

            $file = fopen($tmp_name,'rb');

            $data = fread($file,filesize($tmp_name));

            fclose($file);

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

         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
   $message.="--{$mime_boundary}--\n";
   if (@mail($to, $subject, $message, $headers))
      echo "Uw bestelling is verzonden";
   else
      echo "Er is iets fout gegaan met het verzenden met uw bestelling.";
} else {
?>
<form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
      <table width="495" border="0" align="center" cellpadding="0" cellspacing="3" class="tekst">
          <tr>
            <td colspan="7" class="body"><strong>Sleutel/Cilinder Bestelformulier</strong></td>
          </tr>
          <tr>
            <td colspan="7" class="body"> </td>
          </tr>
        <tr>
            <td width="131" colspan="1" class="body"> Opdracht Nummer</td>
            <td colspan="3"><input type="text" name="opdrachtnr" class="textfield" id="opdrachtnr"></td>
        </tr>
          <tr>
            <td colspan="1" class="body">Naam Klant</td>
            <td colspan="3"><input type="text" name="fromname" class="textfield" id="fromname"></td>
          </tr>
        <tr>
            <td colspan="1" class="body"> Afleveradres</td>
            <td colspan="3"><textarea cols="16" name="afleveradr" id="afleveradr"></textarea></td>
        </tr>
        <tr>
          <td colspan="1" class="body">Factuuradres</td>
          <td colspan="3"><textarea cols="16" name="factuuradr" id="factuuradr"></textarea></td>
        </tr>
        <tr>
            <td colspan="1" class="body"> Contactpersoon</td>
            <td colspan="3"><input type="text" name="contact" class="textfield" id="contact"></td>
        </tr>
        <tr>
            <td colspan="1" class="body"> Telefoon</td>
            <td colspan="3"><input type="text" name="telefoon" class="textfield" id="telefoon"></td>
        </tr>
        <tr>
            <td colspan="1" class="body"> Fax</td>
            <td colspan="3"><input type="text" name="fax" class="textfield" id="fax"></td>
        </tr>
        <tr>
          <td colspan="1" class="body">E-Mail</td>
          <td colspan="3"><input type="text" name="fromemail" class="textfield" id="fromemail"></td>
        </tr>
        <tr>
            <td colspan="1" class="body">Certificaat (PDF/JPG)</td>
            <td colspan="3"><input type="file" name="file1" id="file1">
            <div id="extra001" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab" tabindex="0">+ Klik hier om een extra certificaat toe te voegen</div>
            <div class="CollapsiblePanelContent">
              <input type="file" name="file2" id="file2">
            </div>
          </div>
          </td>
        </tr>
        <tr>
          <td colspan="1" rowspan="7" align="center" valign="bottom" class="body"><img src="afbeeldingen/sleutel.jpg" alt="sleutel" width="85" height="166" align="middle"></td>
          <td width="96" align="center" valign="middle"><strong>Sleutel nummer</strong></td>
          <td width="101" align="center" valign="middle"><strong>Aantal</strong></td>
          <td width="104" align="center" valign="middle"><strong>Sluitplan nummer</strong></td>
        </tr>
        <tr>
          <td><input name="fax2" type="text" class="textfield" id="fax2" size="10"></td>
          <td><input name="fax6" type="text" class="textfield" id="fax6" size="10"></td>
          <td><input name="fax10" type="text" class="textfield" id="fax10" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
        <td colspan="3">
        <div id="extra002" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab" tabindex="0">+ Klik hier om meer sleutels toe te voegen</div>
            <div class="CollapsiblePanelContent">
            <table border="0" cellpadding="0" cellspacing="3" style="margin-left:-3px; margin-right:-3px;">
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
             </table>
          </div>
          </div>
        </td>
        </tr>
        <tr>
            <td height="77" colspan="7" align="left" style="padding-top:10px; padding-bottom:10px; text-align: center;"><p><strong>
              GHS sleutel; Past op alle bestaande cilinders in sluitplan.<br>
              HS sleutel; Past op cilinders onder een bepaalde hoofdgroep.<br>
            Mono sleutel; Past enkel op cilinder met specifiek cilindernummer.</strong>
            </p>
            <p><img src="afbeeldingen/cilinders2.jpg" width="519" height="85" alt="cilinders"></p></td>
        </tr>
        <tr>
          <td align="center" valign="middle"><strong>Soort cilinder</strong></td>
          <td align="center" valign="middle"><strong>Cilinder nummer</strong></td>
          <td align="center" valign="middle"><strong>Aantal</strong></td>
          <td colspan="2" align="center" valign="middle"><p><img src="afbeeldingen/maatvoering.jpg" width="105" height="48" alt="maatvoering"><strong> Maatvoering</strong></p></td>
          <td width="62" align="center" valign="middle"><strong>Sluitplan nummer</strong></td>
        </tr>
        <tr>
          <td align="left"><input name="fax31" type="text" class="textfield" id="fax31" size="10"></td>
          <td align="left"><input name="fax30" type="text" class="textfield" id="fax30" size="10"></td>
          <td align="left"><input name="fax29" type="text" class="textfield" id="fax29" size="10"></td>
          <td lign="left"><input name="fax22" type="text" class="textfield" id="fax22" value="A" size="10"></td>
          <td align="left"><input name="fax21" type="text" class="textfield" id="fax21" value="B" size="10"></td>
          <td align="left"><input name="fax14" type="text" class="textfield" id="fax14" size="10"></td>
        </tr>
        <tr>
          <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
          <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
          <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
          <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
          <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
          <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
        </tr>
        <tr>
          <td colspan="7" align="center">
          	<div id="extra003" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab" tabindex="0">+ Klik hier om meer cilinders toe te voegen</div>
            <div class="CollapsiblePanelContent">
            <table border="0" cellpadding="0" cellspacing="3" style="margin-left:-3px; margin-right:-3px;">
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
            </table>
            </div>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="7" align="center"><input type="submit" value="Verzenden" name="submit" onClick="return validate();">
            <input type="reset" value="Alles Wissen" name="reset"></td>
        </tr>
      </table>   
</form>
<?php } ?>
<script type="text/javascript">
<!--
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("extra001", {contentIsOpen:false});
var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("extra002", {contentIsOpen:false});
var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("extra003", {contentIsOpen:false});
//-->

</script>
</body>
</html>

 

Now I have a little problem with the message part, all html is visible when I received an email, like this:

 

<table cellspacing="0" cellpadding="8" border="0" width="400">
            <tr>
                <td colspan="2"></td>
            </tr>
            <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">Lennart</td>
            </tr>
            <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">dlennartd@zeelandnet.nl</td>
              </tr>
            <td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
         </table>

 

I have no problems with the attachments, only the message is a pain in the butt, I hope somebody can tell me what I'm doing wrong.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/241068-mailscript-send-html-to-mailbox/
Share on other sites

Did you set the content-type to 'text/html' ?

 

The attachments don't work when I do this, but the message is displaying correctly.

 

messager.jpg

 

$message = "This is a multi-part message in MIME format.\n\n" .

 

should be:

 

$message .= "This is a multi-part message in MIME format.\n\n" .             //  mark the extra dot before the =  !!

 

This didn't made any difference. :(

Lennart, to speed things up for yourself, consider using a package for sending mail: Libmail, PHPMailer, Swiftmail. And look at http://www.pfz.nl/forum/topic/455-s?do=findComment&comment=3247

 

You are right, using a package would be a better idea. I used PHPMailer now, but my attachments (.jpg pictures) get converted into .bin files and I don't understand why.

I used PHPMailer now, but my attachments (.jpg pictures) get converted into .bin files and I don't understand why.

Can you show the code where that happens?

 

This is the code I use to send the mail with attachment:

 

require("phpmailer.inc.php");

$mail = new phpmailer;

//$mail->IsSMTP(); // set mailer to use SMTP
$mail->From = "$fromemail";
$mail->FromName = "$fromname";
$mail->Host = "smtp1.site.com;smtp2.site.com"; // specify main and backup server
$mail->AddAddress("duivenvoorde@breur.com", "Lennart Duivenvoorde");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("$file1"); // add attachments
$mail->AddAttachment("$file2");

$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Sleutel/Cilinder Bestelformulier";
$mail->Body = '<table cellspacing="0" cellpadding="8" border="0" width="400">
<tr>
<td colspan="2"></td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fromname.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fromemail.'</td>
</tr>
<td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
</table>';
$mail->Send(); // send message

 

This is the PHPmailer I use:

 

http://phpmailer.worxware.com/

According to the documentation, the syntax should be:

 

The AddAttachment function has four arguments:

 

AddAttachment(PATH_TO_FILE, FILENAME, ENCODING, HEADER_TYPE)

 

The PATH_TO_FILE is naturally the full path of the header you want to send. Application/octet-stream is default.

 

What is the contents of your variables $file1 and $file2 ?

What is the contents of your variables $file1 and $file2 ?

 

file1: G:\lennart\Breur logo.jpg

file2: G:\lennart\Opdrachtnummer.doc

 

<input type="file" name="file1" id="file1">

<input type="file" name="file2" id="file2">

 

The full code I use looks like this:

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Sleutel bestelling</title>
<style type="text/css">
<!--
.tekst {
font-family: Verdana, Geneva, sans-serif;
font-size: 10px;
}
-->
</style>
<link href="css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css">
<script src="js/SpryCollapsiblePanel.js" type="text/javascript"></script>
</head>

<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   // we'll begin by assigning the To address and message subject
   $to="duivenvoorde@breur.com";
   $subject="Sleutel/Cilinder Bestelformulier";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // now we'll build the message headers
   $headers = "From: $from\r\n" .
   "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=iso-8859-1\r\n" .
      " boundary=\"{$mime_boundary}\"";
  
  $headers  .= "--$num\r\n";

        // This two steps to help avoid spam   

    $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
    $headers .= "X-Mailer: PHP v".phpversion()."\r\n";         

        // With message
       
/*    $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
       $headers .= "Content-Transfer-Encoding: 8bit\r\n";
       $headers .= "".$message."\n";
       $headers .= "--".$num."\n"; */

   // here, we'll start the message body.
   // this is the text that will be displayed
   // in the e-mail
   $message= '<table cellspacing="0" cellpadding="8" border="0" width="400">
            <tr>
                <td colspan="2"></td>
            </tr>
            <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fromname.'</td>
            </tr>
            <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fromemail.'</td>
              </tr>
            <td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
         </table>';

   // next, we'll build the invisible portion of the message body
   // note that we insert two dashes in front of the MIME boundary 
   // when we use it
   $message .= "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
   $message . "\n\n";

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){
      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){

            // open the file for a binary read
            $file = fopen($tmp_name,'rb');

            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));

            // close the file
            fclose($file);

            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }

         // now we'll insert a boundary to indicate we're starting the attachment
         // we have to specify the content type, file name, and disposition as
         // an attachment, then add the file content.
         // NOTE: we don't set another boundary to indicate that the end of the 
         // file has been reached here. we only want one boundary between each file
         // we'll add the final one after the loop finishes.
         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
   // here's our closing mime boundary that indicates the last of the message
   $message.="--{$mime_boundary}--\n";
   // now we just send the message
   if (@mail($to, $subject, $message, $headers))
      echo "Uw bestelling is verzonden";
   else
      echo "Er is iets fout gegaan met het verzenden met uw bestelling.";
} else {
?>
<form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
      <table width="495" border="0" align="center" cellpadding="0" cellspacing="3" class="tekst">
          <tr>
            <td colspan="7" class="body"><strong>Sleutel/Cilinder Bestelformulier</strong></td>
          </tr>
          <tr>
            <td colspan="7" class="body"> </td>
          </tr>
        <tr>
            <td width="131" colspan="1" class="body"> Opdracht Nummer</td>
            <td colspan="3"><input type="text" name="opdrachtnr" class="textfield" id="opdrachtnr"></td>
        </tr>
          <tr>
            <td colspan="1" class="body">Naam Klant</td>
            <td colspan="3"><input type="text" name="fromname" class="textfield" id="fromname"></td>
          </tr>
        <tr>
            <td colspan="1" class="body"> Afleveradres</td>
            <td colspan="3"><textarea cols="16" name="afleveradr" id="afleveradr"></textarea></td>
        </tr>
        <tr>
          <td colspan="1" class="body">Factuuradres</td>
          <td colspan="3"><textarea cols="16" name="factuuradr" id="factuuradr"></textarea></td>
        </tr>
        <tr>
            <td colspan="1" class="body"> Contactpersoon</td>
            <td colspan="3"><input type="text" name="contact" class="textfield" id="contact"></td>
        </tr>
        <tr>
            <td colspan="1" class="body"> Telefoon</td>
            <td colspan="3"><input type="text" name="telefoon" class="textfield" id="telefoon"></td>
        </tr>
        <tr>
            <td colspan="1" class="body"> Fax</td>
            <td colspan="3"><input type="text" name="fax" class="textfield" id="fax"></td>
        </tr>
        <tr>
          <td colspan="1" class="body">E-Mail</td>
          <td colspan="3"><input type="text" name="fromemail" class="textfield" id="fromemail"></td>
        </tr>
        <tr>
            <td colspan="1" class="body">Certificaat (PDF/JPG)</td>
            <td colspan="3"><input type="file" name="file1" id="file1">
            <div id="extra001" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab" tabindex="0">+ Klik hier om een extra certificaat toe te voegen</div>
            <div class="CollapsiblePanelContent">
              <input type="file" name="file2" id="file2">
            </div>
          </div>
          </td>
        </tr>
        <tr>
          <td colspan="1" rowspan="7" align="center" valign="bottom" class="body"><img src="afbeeldingen/sleutel.jpg" alt="sleutel" width="85" height="166" align="middle"></td>
          <td width="96" align="center" valign="middle"><strong>Sleutel nummer</strong></td>
          <td width="101" align="center" valign="middle"><strong>Aantal</strong></td>
          <td width="104" align="center" valign="middle"><strong>Sluitplan nummer</strong></td>
        </tr>
        <tr>
          <td><input name="fax2" type="text" class="textfield" id="fax2" size="10"></td>
          <td><input name="fax6" type="text" class="textfield" id="fax6" size="10"></td>
          <td><input name="fax10" type="text" class="textfield" id="fax10" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
          <td><input name="fax3" type="text" class="textfield" id="fax3" size="10"></td>
          <td><input name="fax7" type="text" class="textfield" id="fax7" size="10"></td>
          <td><input name="fax11" type="text" class="textfield" id="fax11" size="10"></td>
        </tr>
        <tr>
        <td colspan="3">
        <div id="extra002" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab" tabindex="0">+ Klik hier om meer sleutels toe te voegen</div>
            <div class="CollapsiblePanelContent">
            <table border="0" cellpadding="0" cellspacing="3" style="margin-left:-3px; margin-right:-3px;">
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
                <tr>
                  <td><input name="fax5" type="text" class="textfield" id="fax5" size="10"></td>
                  <td><input name="fax9" type="text" class="textfield" id="fax9" size="10"></td>
                  <td><input name="fax13" type="text" class="textfield" id="fax13" size="10"></td>
                </tr>
             </table>
          </div>
          </div>
        </td>
        </tr>
        <tr>
            <td height="77" colspan="7" align="left" style="padding-top:10px; padding-bottom:10px; text-align: center;"><p><strong>
              GHS sleutel; Past op alle bestaande cilinders in sluitplan.<br>
              HS sleutel; Past op cilinders onder een bepaalde hoofdgroep.<br>
            Mono sleutel; Past enkel op cilinder met specifiek cilindernummer.</strong>
            </p>
            <p><img src="afbeeldingen/cilinders2.jpg" width="519" height="85" alt="cilinders"></p></td>
        </tr>
        <tr>
          <td align="center" valign="middle"><strong>Soort cilinder</strong></td>
          <td align="center" valign="middle"><strong>Cilinder nummer</strong></td>
          <td align="center" valign="middle"><strong>Aantal</strong></td>
          <td colspan="2" align="center" valign="middle"><p><img src="afbeeldingen/maatvoering.jpg" width="105" height="48" alt="maatvoering"><strong> Maatvoering</strong></p></td>
          <td width="62" align="center" valign="middle"><strong>Sluitplan nummer</strong></td>
        </tr>
        <tr>
          <td align="left"><input name="fax31" type="text" class="textfield" id="fax31" size="10"></td>
          <td align="left"><input name="fax30" type="text" class="textfield" id="fax30" size="10"></td>
          <td align="left"><input name="fax29" type="text" class="textfield" id="fax29" size="10"></td>
          <td lign="left"><input name="fax22" type="text" class="textfield" id="fax22" value="A" size="10"></td>
          <td align="left"><input name="fax21" type="text" class="textfield" id="fax21" value="B" size="10"></td>
          <td align="left"><input name="fax14" type="text" class="textfield" id="fax14" size="10"></td>
        </tr>
        <tr>
          <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
          <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
          <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
          <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
          <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
          <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
        </tr>
        <tr>
          <td colspan="7" align="center">
          	<div id="extra003" class="CollapsiblePanel">
            <div class="CollapsiblePanelTab" tabindex="0">+ Klik hier om meer cilinders toe te voegen</div>
            <div class="CollapsiblePanelContent">
            <table border="0" cellpadding="0" cellspacing="3" style="margin-left:-3px; margin-right:-3px;">
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
                <tr>
                  <td align="left"><input name="fax33" type="text" class="textfield" id="fax33" size="10"></td>
                  <td align="left"><input name="fax38" type="text" class="textfield" id="fax38" size="10"></td>
                  <td align="left"><input name="fax28" type="text" class="textfield" id="fax28" size="10"></td>
                  <td align="left"><input name="fax23" type="text" class="textfield" id="fax23" value="A" size="10"></td>
                  <td align="left"><input name="fax20" type="text" class="textfield" id="fax20" value="B" size="10"></td>
                  <td align="left"><input name="fax15" type="text" class="textfield" id="fax15" size="10"></td>
                </tr>
            </table>
            </div>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="7" align="center"><input type="submit" value="Verzenden" name="submit" onClick="return validate();">
            <input type="reset" value="Alles Wissen" name="reset"></td>
        </tr>
      </table>   
</form>
<?php } ?>
<script type="text/javascript">
<!--
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("extra001", {contentIsOpen:false});
var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("extra002", {contentIsOpen:false});
var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("extra003", {contentIsOpen:false});
//-->

</script>
</body>
</html>

 

You can find it at http://breur.com/phpmailer/mail.php

Okay, too bad for your time spent.  :-[

I copied your script to my server, changed the to-address, and now I think I can see what's wrong. Attachments are added to you message, and separated by boundaries. Those boundaries should be unique for each attachment. Therefor you added a variable in your script, called $num, and you -correctly- integrated this in you boundary. But you don't use and/or increment this, so al your boundaries have the same name.  :P

Furthermore: if you want to compose your own headers, each line you want to make should end with "\r\n" which means: 'go to the beginning of the next line'. http://php.net/manual/en/function.mail.php

All-in-all I would strongly recommend to switch to using one of the mentioned EASY  :D mailing-packages.

Okay, too bad for your time spent.  :-[

I copied your script to my server, changed the to-address, and now I think I can see what's wrong. Attachments are added to you message, and separated by boundaries. Those boundaries should be unique for each attachment. Therefor you added a variable in your script, called $num, and you -correctly- integrated this in you boundary. But you don't use and/or increment this, so al your boundaries have the same name.  :P

Furthermore: if you want to compose your own headers, each line you want to make should end with "\r\n" which means: 'go to the beginning of the next line'. http://php.net/manual/en/function.mail.php

All-in-all I would strongly recommend to switch to using one of the mentioned EASY  :D mailing-packages.

 

Thanks for your advise, this makes me understand what I did wrong. (not how to fix it, yet)

 

I used one of those mailing packages, PHPmailer, as I posted above, thats where I got the .bin problem. :(

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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