Jump to content

Need help in sending an attachement through email


ramzyteeny

Recommended Posts

This code is for a php form that send an email but the thing is that it s not sending the attchement.

So i am asking id anyone could help

Ramzy

 

 

<?php

 

$to = '[email protected]' ;

$from = $_REQUEST['email'] ;

$name = $_REQUEST['fn'] ;

$headers = "From: $from";

$subject = "Design Competition Information";

 

foreach($_POST['checkbox'] as $value) {

$check_msg .= "I choosed: $value\n";

}

 

 

$fileatt = $_FILES['attach']['tmp_name'];

$fileatt_type = $_FILES['attach']['type'];

$fileatt_name = $_FILES['attach']['name'];

 

if (is_uploaded_file($fileatt)) {

 

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

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

fclose($file);

 

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

 

$headers .= "\nMIME-Version: 1.0\n" .

"Content-Type: multipart/mixed;\n" .

" boundary=\"{$mime_boundary}\"";

 

$subject = "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" .

$subject . "\n\n";

 

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

 

$subject .= "--{$mime_boundary}\n" .

"Content-Type: {$fileatt_type};\n" .

" name=\"{$fileatt_name}\"\n" .

//"Content-Disposition: attachment;\n" .

//" filename=\"{$fileatt_name}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .

$data . "\n\n" .

"--{$mime_boundary}--\n";

}

 

$fields = array();

$fields{"fn"} = "fn";

$fields{"ln"} = "ln";

$fields{"Gender"} = "Gender";

$fields{"university"} = "university";

$fields{"major"} = "major";

$fields{"tel"} = "tel";

$fields{"email"} = "email";

$fields{"address"} = "address";

$fields{"select"} = "select";

$fields{"comments"} = "comments";

$fields{"check_msg"} = "$check_msg";

 

 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

 

 

$headers2 = "From: [email protected]";

$subject2 = "Thank you for contacting us";

$autoreply = "Thank you for contacting us.

Somebody will get back to you as soon as possible, please consult our website at www.-------.com";

 

if($from == '') {print "You have not entered an email, please go back and try again";}

else {

if($name == '') {print "You have not entered a name, please go back and try again";}

else {

$send = mail($to, $subject, $body, $headers);

$send2 = mail($from, $subject2, $autoreply, $headers2);

if($send)

{header( "Location: http://www.-----.php" );}

else

{print "We encountered an error sending your mail, please notify [email protected]"; }

}

}

?>

Archived

This topic is now archived and is closed to further replies.

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