Problem attaching file into form

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 3
Joined: Mon Jun 14, 2004 8:31 am

Problem attaching file into form

Postby amvc » Tue Jun 15, 2004 5:59 am

i made a simple html form where its possible to attach a file, to send this information by email i used a .php file. The problem is that while all the information in the form is received correctly, the attached file is not.
I think the problem has to do with uploading the file into the server (i dont know how to do that). Here are the html and php files codes i've used:


Code: Select all

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

<body bgcolor="#FFFFFF" text="#000000">
<form name=a method=POST action="submit.php" enctype="multipart/form-data" autocomplete=off>
  <input type="hidden" name="to" value="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <td valign="middle" align="left" width="14%" class="tit1">Nome&nbsp;</td>
      <td valign="top" colspan="2">
        <input type="text" name="nome" size="50" >
      <td valign="middle" align="left" width="14%" class="tit1"><span class="form">Tel./Telm.</span>&nbsp;</td>
      <td valign="top" colspan="2">
        <input type="text" name="Telefone" size="50">
      <td valign="middle" align="left" width="14%" class="tit1">Email&nbsp;</td>
      <td valign="top" colspan="2">
        <input type="text" name="Email" size="50">
      <td height="2" width="14%" align="left" valign="middle" class="tit1">&Aacute;rea
      <td height="2" valign="top" colspan="2">
        <input type="text" name="&Aacute;rea" size="50" value="">
      <td width="14%" class="tit1">Anexar C.V. </td>
      <td colspan="2" align="left" valign="middle"> <br>
        <input name="message" type="file" size="25">
      <td width="14%">&nbsp;</td>
      <td align="right" width="25%">
        <input type="submit" value="Enviar" name="submit2">
        <input type="reset" value="Limpar" name="reset2">
      <td align="right" width="61%">&nbsp;</td>


Code: Select all

// --- Create Message Text
$temp.=" $field : = $HTTP_POST_VARS[$field] \n";

// Read POST request params into global vars
$to = $_POST['to'];
$from = $_POST['Email'];
$message = $temp;

// Obtain file upload vars
$fileatt = $_FILES['Logo']['tmp_name'];
$fileatt_type = $_FILES['Logo']['type'];
$fileatt_name = $_FILES['Logo']['name'];

$headers = "From: $from";

if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$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" .

// Send the message
$ok = @mail($to, "New Request", $message, $headers);

// -- Send Another Message to SENDER
$message = '
a:hover { color: red }
v\:* { behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
<body link="#0000FF" vlink="#0000FF" alink="#0000FF">
<p><font face="Verdana" size="2">OMID SOFT Open Source Free Scripts.<br>
Our records indicate that you selected OMID SOFT\'s Open Source Free Scripts.<br>
This message is to confirm that your order has been submitted.<br>
Please do not send duplicates of your e-mail unless you want to provide additional information.<br>
Thank you.<br>
OMID SOFT Open Source Free Scripts Team.</font></p>

$to = $HTTP_POST_VARS['Email'];
$subject = "Candidatura Enviada";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "To: ". $to ."\r\n";
$headers .= "From: <>\r\n";

mail($to, $subject, $message, $headers);

// -- Goto Another Page

I hope that someone is able to help me.


User avatar
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Aug 10, 2008 11:18 am
Location: New York, Central New York

Re: Problem attaching file into form

Postby 2nejunkie » Sun Aug 10, 2008 11:53 am

I am having the same problem.

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 5 guests