2016-03-30 18 views
-1

So versuche ich, ein Formular mit Anhang zu senden, aber wenn ich $ Header in meine E-Mail einfügen sendet es nicht: mail("[email protected]", $subject, $message, $headers) und wenn ich $ Header aus meinem Code entfernen Mail gesendet wird aber der Bild-Anhang versenden zu sein, ist Datentext und nicht das tatsächliche Befestigung Bild png form.Everything ist vollgestopft bis w/o Grenze habe ich versucht, Code von dieser Website: Click Me
Was ich falsch unten ?:PHP-Mail konnte nicht gesendet werden, wenn enthalten Header

in meinem Code zu tun
<?php 
if(isset($_POST['submit']) && $_POST['submit']=='Submit') 

{ 

$to="[email protected]"; 
$subject="File sent by ".$_POST['name']; 

// get the sender's name and email address 
// we'll just plug them a variable to be used later 

$from = stripslashes($_POST['name'])."<".stripslashes($_POST['email']).">"; 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['comment']; 

// generate a random string to be used as the boundary marker 
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; 
if($_FILES['filename']['tmp_name'] != ''){ 
// store the file information to variables for easier access 
$tmp_name = $_FILES['filename']['tmp_name']; 
$type = $_FILES['filename']['type']; 
$file_name = $_FILES['filename']['name']; 
$size = $_FILES['filename']['size']; 
} 
// here we'll hard code a text message 
// again, in reality, you'll normally get this from the form submission 

if($tmp_name != ''){ 
$message = "nn Name: $name nn Email: $email_address nnMessage: nn $message nnHere is your file: $file_name"; 
} 
else{ 
$message = "nn Name: $name nn Email: $email_address nnMessage: nn $message."; 
} 
// if the upload succeded, the file will exist 
if($tmp_name != ''){ 
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 build the message headers 
    $headers = "From: $fromrn"; 
if($tmp_name != ''){ 
$headers .= "MIME-Version: 1.0rn" . 
"Content-Type: multipart/mixed;rn" ; 

// next, we'll build 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.nn" . 
"Content-Type:text/plain;charset=iso-8859-1" . 
"Content-Transfer-Encoding: 7bitnn" . 
$message . "nn"; 

// 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 and set another boundary to 
// indicate that the end of the file has been reached 

$message .= 
"Content-Type: ".$type."" . 
" name=".$file_name."n" . 
//"Content-Disposition: attachment;n" . 
//" filename="{$fileatt_name}"n" . 
"Content-Transfer-Encoding: base64nn" . 
$data . "nn" ; 
} 
// now we just send the message 
if (mail("[email protected]", $subject, $message, $headers)) 
echo "<div class='msg msg-ok'><p><strong>Message Sent</strong></p></div><br><br>"; 
else 
echo "<div class='msg msg-ok'><p><strong>Message sending failed</strong></p></div><br><br>"; 
} 

?> 
<html> 
<body> 
<form id="comment" action="atta.php" method="post" enctype="multipart/form-data"> 
<label>Name <span></span></label> 
<input type="text" name="name" id="name"> 
<label>Email <span></span></label> 
<input type="text" name="email" id="email"> 
<label>Comment <span></span></label> 
<input type="text" name="comment" id="email"> 
<label>Upload file <span></span></label> 
<input type="file" name="filename" id="file"> 
<input type="submit" name="submit" value="Submit"> 
</form> 
</body> 
</html> 

Antwort

1
$headers .= "MIME-Version: 1.0\r\n"; //use \r\n 

Hoffe es hilft :)

+0

Ok, aber jetzt hat der Anhang keinen Namen und hat auch keinen Dateityp –

+0

$ headers. = "MIME-Version: 1.0 \ r \ n". "Inhaltstyp: mehrteilig/gemischt; \ r \ n"; –

+0

Nein noch hat der Anhang noname und hat keine Erweiterung, so dass es in keinem Programm geöffnet –

Verwandte Themen