Gå til innhold

Problem med mailform med vedlegg ? HJELP!


Anbefalte innlegg

Jeg har et mailform script som skal sende med vedlegg fra en nettside.

Scriptet sender mailen og alt det der, men maien jeg får er bare ren html kode og vedlegget er i tusenvis av tegn nederst i mailen.

 

Her er php koden...

<?php

// site info

$SiteName = "http://www.domene.no";

$SiteEmail = "[email protected]";

$SiteUserName = "navn";

$subject = 'Send vedlegg.';

$ip = $_ENV['REMOTE_ADDR'];

$sysinfo = $_ENV['HTTP_USER_AGENT'];

$refresh = "<script>document.location.href='?op=sendt'</script>";

// site info

 

// error messages and language

$err_email = "Ugyldig e-post adresse";

$err_back = '<a href="javascript:window.history.back()">Go back and correct the error</a>';

$mail_desc = 'wishes to be contacted';

$form_name = "Navn";

$form_email = "E-post";

$form_address = "Adresse";

$form_phone = "Telefon";

$form_message = "Fritekst";

$form_submit = "Send";

$form_att_1 = "Vedlegg";

// $form_att_2 = "Attachment 2";

// error messages and language

 

// Post vars

$email = stripslashes($_POST['email']);

$name = stripslashes($_POST['name']);

$address = stripslashes($_POST['address']);

$phone = stripslashes($_POST['phone']);

$message2 = stripslashes($_POST['message']);

// Post vars

 

// mail form

$form = '

 

<div class="FormWrap">

<table>

<form action="?op=send" method="post" enctype="multipart/form-data" name="contact">

  <tr>

    <td class="FormTittel">'.$form_name.':</td>

    <td class="FormInput"><input type="text" name="name"></td>

  </tr>

  <tr>

    <td class="FormTittel">'.$form_email.':</td>

    <td class="FormInput"><input type="text" name="email"></td>

  </tr>

  <tr>

    <td class="FormTittel">'.$form_address.':</td>   

    <td class="FormInput"><input type="text" name="address"></td> 

</tr>

  <tr>

    <td class="FormTittel">'.$form_phone.':</td>

    <td class="FormInput"><input type="text" name="phone"></td> 

  </tr>

  <tr>

    <td class="FormTittel">'.$form_att_1.':</td>

    <td class="FormInput"><input class="FormInputFile" type="file" name="file1"></td>

  </tr>

  <tr>

    <td class="FormTittel">'.$form_message.':</td>

    <td class="FormInput"><textarea name="message" cols="30" rows="5"></textarea></td> 

  </tr>

  <tr>

    <td> </td>

    <td class="FormKnapp"><input type="submit" name="Submit" value="'.$form_submit.'"></td>

  </tr>

</form>

</table>

</div>

 

';

// mail form

 

// mail body

$html ='

<html>

<head>

<title>'.$SiteUserName.'</title>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<style type="text/css">

<!--

.style1 {

color: #FFFFFF;

font-weight: bold;

}

-->

</style>

</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF">

<center>

<table width="600" border="2" align="center" cellpadding="15" bordercolor="#330099">

<tr bgcolor="#000099">

  <td colspan="2" align="center"><h2 class="style1">Silverviper.com</h2></td>

</tr>

<tr>

  <td height="24" colspan="2" bgcolor="#FFFFFF">'.$name.', '.$mail_desc.'</td>

</tr>

<tr>

  <td width="257" height="115" align="center" valign="top">

  <ul>

  <li><div align="left"><a href="mailto:'.$email.'">'.$name.'</a></div></li>

  <li><div align="left"><a href="mailto:'.$email.'">'.$email.'</a></div></li>

  <li><div align="left">'.$phone.'</div></li>     

  <li><div align="left">'.$address.'</div></li>

  </ul></td>

  <td width="269" valign="top">

  <ul>

  <li><div align="left">IP '.$ip.'</div></li>     

  <li><div align="left">Agent '.$sysinfo.'</div></li>

  </ul</td>

</tr>

<tr>

  <td colspan="2">'.$message2.'</td>

</tr>

<tr>

  <td colspan="2" align="center"></font></font></td>

</tr>

</table>

</center>

</body>

</html>';

// mail body

 

// sent message

$sent = '

<table>

<tr>

  <td>Contact</td>

  <td>&nbsp</td>

  <td>&nbsp</td>

</tr>

<tr>

  <td>&nbsp</td>

  <td>Message sent</td>

  <td>&nbsp</td>

</tr>

<tr>

  <td>&nbsp</td>

  <td>&nbsp</td>

  <td>&nbsp</td>

</tr>

</table>';

// sent message

 

// validate email

function validate_email($email) {

  $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";

  $valid = 0;

  if (eregi($regexp, $email))  {

      list($username,$domaintld) = split("@",$email);

      if (getmxrr($domaintld,$mxrecords))

        $valid = 1;

  } else {

      $valid = 0;

  }

  return $valid;

}

// validate email

 

if ($_GET["op"] == "sendt") {

print $sent;

} elseif ($_GET["op"] == "send"){

 

// generate a random string to be used as the boundary marker

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

 

// mail headers

 

$headers  = "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: multipart/mixed; charset=iso-8859-1\r\n" . " boundary=\"{$mime_boundary}\"";

$headers .= "To: $SiteUserName <$SiteEmail>" . "\r\n";

$headers .= "From: $name <$email>" . "\r\n";

$headers .= 'Cc:' . "\r\n";

$headers .= 'Bcc:' . "\r\n";

 

    $message = $html; // insert body content

 

  // 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

  // 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/html; 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 (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));

        }

 

        // 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 (validate_email($email)) {

  @mail($SiteEmail, $subject, $message, $headers);

  print $refresh;

} else {

    print $err_email.'<br>';

    print $err_back;

    exit();

}

 

} else {

print $form;

}

 

?>

 

Her er slik mailen min ser ut. Og ja den støtter html mail

 

 

This is a multi-part message in MIME format.

 

--==Multipart_Boundary_x0e7332b76ef571257fd323428836e136x

Content-Type: text/html; charset="iso-8859-1"

Content-Transfer-Encoding: 7bit

 

 

<html>

<head>

<title>Carl Otto Jansen</title>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<style type="text/css">

<!--

.style1 {

color: #FFFFFF;

font-weight: bold;

}

-->

</style>

</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#0000FF">

<center>

<table width="600" border="2" align="center" cellpadding="15" bordercolor="#330099">

<tr bgcolor="#000099">

  <td colspan="2" align="center"><h2 class="style1">Silverviper.com</h2></td>

</tr>

<tr>

  <td height="24" colspan="2" bgcolor="#FFFFFF">bazzo, wishes to be contacted</td>

</tr>

<tr>

  <td width="257" height="115" align="center" valign="top">

  <ul>

  <li><div align="left"><a href="mailto:[email protected]">bazzo</a></div></li>

  <li><div align="left"><a href="mailto:[email protected]">[email protected]</a></div></li>

  <li><div align="left">323223</div></li>     

  <li><div align="left">dffgh</div></li>

  </ul></td>

  <td width="269" valign="top">

  <ul>

  <li><div align="left">IP </div></li>     

  <li><div align="left">Agent </div></li>

  </ul</td>

</tr>

<tr>

  <td colspan="2">dsfsdf</td>

</tr>

<tr>

  <td colspan="2" align="center">2005 © Silverviper</font></font></td>

</tr>

</table>

</center>

</body>

</html>

 

--==Multipart_Boundary_x0e7332b76ef571257fd323428836e136x

Content-Type: image/pjpeg;

name="Winter.jpg"

Content-Disposition: attachment;

filename=""

Content-Transfer-Encoding: base64

 

/9j/4AAQSkZJRgABAgEAYABgAAD/7RBKUGhvdG9zaG9wIDMuMAA4QklNA+0KUmVzb2x1dGlvbgAA

AAAQAGAAAAABAAEAYAAAAAEAAThCSU0EDRhGWCBHbG9iYWwgTGlnaHRpbmcgQW5nbGUAAAAABAAA

AHg4QklNBBkSRlggR2xvYmFsIEFsdGl0dWRlAAAAAAQAAAAeOEJJTQPzC1ByaW50IEZsYWdzAAAA

CQAAAAAAAAAAAQA4QklNBAoOQ29weXJpZ2h0IEZsYWcAAAAAAQAAOEJJTScQFEphcGFuZXNlIFBy

aW50IEZsYWdzAAAAAAoAAQAAAAAAAAACOEJJTQP1F0NvbG9yIEhhbGZ0b25lIFNldHRpbmdzAAAA

SAAvZmYAAQBsZmYABgAAAAAAAQAvZmYAAQChmZoABgAAAAAAAQAyAAAAAQBaAAAABgAAAAAAAQA1

AAAAAQAtAAAABgAAAAAAAThCSU0D+BdDb2xvciBUcmFuc2ZlciBTZXR0aW5ncwAAAHAAAP//////

//////////////////////8D6AAAAAD/////////////////////////////A+gAAAAA////////

/////////////////////wPoAAAAAP////////////////////////////8D6AAAOEJJTQQIBkd1

aWRlcwAAAAAQAAAAAQAAAkAAAAJAAAAAADhCSU0EHg1VUkwgb3ZlcnJpZGVzAAAABAAAAAA4QklN

BBoGU2xpY2VzAAAAAHUAAAAGAAAAAAAAAAAAAAJYAAADIAAAAAoAVQBuAHQAaQB0AGwAZQBkAC0A

 

osv. osv i tusen linjer til...

Lenke til kommentar
Videoannonse
Annonse

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...