Hallo liebes Forum,
ich habe da ein Kontaktformular mit Dateianhang, welches per E-Mail versendet werden soll.
Die Anhänge werden gesendet, doch die Felder die man ausfüllt bleiben leer in der Mail. Bin neu in/bei PHP und komme nicht so zurecht mit diesem Script. Über eure Hilfe freue ich mich sehr.
Dazu mal der Code:
<?php
$to = ""; -------------------------- Die Adresse habe ich absichtlich rausgenommen.
$subject= "Bewerbung";
$todayis = date("l, F j, Y, g:i a") ;
$message = "
Date ------- $todayis
Name ------ $name
Last Name ------- $lastname
Email ----------- $email
Company --------- $cmname
Address --------- $add
City ------------ $city
State ----------- $state
Zip ------------- $zip
Phone ----------- $phone
Fax ------------- $fax
Message --------- $comments
";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $email\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$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 "Mail sent successfully.";
else
echo "Error in mail";
?>
Wäre echt prima wenn Ihr mir da helfen könntet.
Und hier noch der HTML-Code:
<table width="90%" border="0" cellpadding="0" cellspacing="0" >
<tr><td align="center" valign="top"> </td></tr>
<tr>
<td align="center" valign="top"><form action="sendmail.php" method="post" name="rfqfrm" id="rfqfrm" enctype="multipart/form-data">
<table width="500" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="150" align="right" valign="middle">* First Name:</td>
<td align="left" valign="middle"><input name="name" type="text" id="name" size="25"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">* Last Name: </td>
<td align="left" valign="middle"><input name="lastname" type="text" id="lastname" size="25"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">* Email:</td>
<td align="left" valign="middle"><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Company Name: </td>
<td align="left" valign="middle"><input name="cmname" type="text" id="cmname" size="15"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Address:</td>
<td align="left" valign="middle"><input name="add" type="text" id="add" size="35"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">City:</td>
<td align="left" valign="middle"><input name="city" type="text" id="city" size="30"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">State:</td>
<td align="left" valign="middle"><table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50"><input name="state" type="text" id="state" size="2"></td>
<td width="50" align="right">Zip: </td>
<td width="200"><input name="zip" type="text" id="zip" size="10"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Phone:</td>
<td align="left" valign="middle"><input name="phone" type="text" id="phone"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Fax:</td>
<td align="left" valign="middle"><input name="fax" type="text" id="fax"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File1:</td>
<td align="left" valign="middle"><input type="file" name="attachFile"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File2:</td>
<td align="left" valign="middle"><input type="file" name="attachFile2"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File3:</td>
<td align="left" valign="middle"><input type="file" name="attachFile3"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File4:</td>
<td align="left" valign="middle"><input type="file" name="attachFile4"></td>
</tr>
<tr>
<td align="right" valign="middle">Attach File5:</td>
<td align="left" valign="middle"><input type="file" name="attachFile5"></td>
</tr>
<tr>
<td width="150" align="right" valign="top">* Please describe your project needs: </td>
<td align="left" valign="middle"><textarea name="comments" cols="30" rows="7" id="comments"></textarea></td>
</tr>
<tr>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"><input type="reset" name="Reset" value="Clear">
<input type="submit" name="Submit2" value="Submit"></td>
</tr>
</table>
</form></td>
</tr>
</table>
Daaaaaanke schön
ich habe da ein Kontaktformular mit Dateianhang, welches per E-Mail versendet werden soll.
Die Anhänge werden gesendet, doch die Felder die man ausfüllt bleiben leer in der Mail. Bin neu in/bei PHP und komme nicht so zurecht mit diesem Script. Über eure Hilfe freue ich mich sehr.
Dazu mal der Code:
<?php
$to = ""; -------------------------- Die Adresse habe ich absichtlich rausgenommen.
$subject= "Bewerbung";
$todayis = date("l, F j, Y, g:i a") ;
$message = "
Date ------- $todayis
Name ------ $name
Last Name ------- $lastname
Email ----------- $email
Company --------- $cmname
Address --------- $add
City ------------ $city
State ----------- $state
Zip ------------- $zip
Phone ----------- $phone
Fax ------------- $fax
Message --------- $comments
";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $email\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$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 "Mail sent successfully.";
else
echo "Error in mail";
?>
Wäre echt prima wenn Ihr mir da helfen könntet.
Und hier noch der HTML-Code:
<table width="90%" border="0" cellpadding="0" cellspacing="0" >
<tr><td align="center" valign="top"> </td></tr>
<tr>
<td align="center" valign="top"><form action="sendmail.php" method="post" name="rfqfrm" id="rfqfrm" enctype="multipart/form-data">
<table width="500" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="150" align="right" valign="middle">* First Name:</td>
<td align="left" valign="middle"><input name="name" type="text" id="name" size="25"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">* Last Name: </td>
<td align="left" valign="middle"><input name="lastname" type="text" id="lastname" size="25"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">* Email:</td>
<td align="left" valign="middle"><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Company Name: </td>
<td align="left" valign="middle"><input name="cmname" type="text" id="cmname" size="15"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Address:</td>
<td align="left" valign="middle"><input name="add" type="text" id="add" size="35"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">City:</td>
<td align="left" valign="middle"><input name="city" type="text" id="city" size="30"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">State:</td>
<td align="left" valign="middle"><table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50"><input name="state" type="text" id="state" size="2"></td>
<td width="50" align="right">Zip: </td>
<td width="200"><input name="zip" type="text" id="zip" size="10"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Phone:</td>
<td align="left" valign="middle"><input name="phone" type="text" id="phone"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Fax:</td>
<td align="left" valign="middle"><input name="fax" type="text" id="fax"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File1:</td>
<td align="left" valign="middle"><input type="file" name="attachFile"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File2:</td>
<td align="left" valign="middle"><input type="file" name="attachFile2"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File3:</td>
<td align="left" valign="middle"><input type="file" name="attachFile3"></td>
</tr>
<tr>
<td width="150" align="right" valign="middle">Attach File4:</td>
<td align="left" valign="middle"><input type="file" name="attachFile4"></td>
</tr>
<tr>
<td align="right" valign="middle">Attach File5:</td>
<td align="left" valign="middle"><input type="file" name="attachFile5"></td>
</tr>
<tr>
<td width="150" align="right" valign="top">* Please describe your project needs: </td>
<td align="left" valign="middle"><textarea name="comments" cols="30" rows="7" id="comments"></textarea></td>
</tr>
<tr>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"><input type="reset" name="Reset" value="Clear">
<input type="submit" name="Submit2" value="Submit"></td>
</tr>
</table>
</form></td>
</tr>
</table>
Daaaaaanke schön
Kommentar