Looking for php code for mail form w/ required fields and attachments

edited August 2006 in Internet & Media
<!-- message -->
<div>Hello.
I'm working on an email form on Dreamweaver and I'm looking for a PHP code to make it work. The form with some required fields would send the submitted information and two image attachments to my email address.
I just started looking at PHP two weeks ago for an answer and the only code that worked for me, so far, was a simple php email form:

<font size="1"><html>
<head></head>
<body>
<h2>Simple Mail Form</h2>
<?
if(isset($submit)) {
//check for email injection attack; refuse if injection
$attack = false;
foreach($_POST as $field => $input) {
$input = stripslashes($input);
if(preg_match('/Content-Type: multipart\/mixed/i', $input)) $attack = true;
if($field != 'comment') {
if(preg_match('/\n/', $input)) $attack = true;
if(preg_match('/\r/', $input)) $attack = true;
}
}
if(!$attack) {
// enter the email addy you want the message sent to:
$to = "email@domain.com";

mail($to, $subject, $comment, $name);
echo "<p>Thank you for your comment! We will respond shortly.</p>";
}
}
else {
?>
<form id="email" method="post">
<p>Name: <input type="text" id="name" name="name" size="30" maxlength="100" /></p>
<p>Subject: <input type="text" id="subject" name="subject" size="30" maxlength="100" /></p>
<p>Comment: <input type="textarea" id="comment" name="comment" cols="30" rows="10">
</p>
<p><input type="submit" name="submit" id="submit" value="Submit" /></p>
</form>
<?
}
?>

</body>
</html></font>

<div align="center">
</div>

However I am looking for a more advanced code for a form with some required fields that can send text and attachments. Any help is duly appreciated.

(here is a page I found earlier but I can't seem to make work)
<a href="http://66.102.7.104/search?q=cache:v97qXlb7m0oJ:www.short-media.com/forum/archive/index.php/t-7019.html+mail+php+form+jpg+gif+attachment&hl=en&gl=us&ct=clnk&cd=4&quot; target="_blank">http://66.102.7.104/search?q=cache:...us&ct=clnk&cd=4</a&gt;

<div align="center">
</div>
here's the Dreamweaver html code for my form:
<div align="center">
</div>
<font size="1"><html>
<head>
<title>Submission Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="submission" method="post" action="" enctype="multipart/form-data">
<p align="center"><font size="6" face="Gill Sans MT"><b>Submission Form</b></font></p>
<table width="589" border="1" cellspacing="0" cellpadding="0" height="111" bgcolor="#999999" bordercolor="#FFFFFF">
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><font size="3" face="Gill Sans MT"><b>Your
Name </b></font><font face="Gill Sans MT"></font></font></div>
</td>
<td width="335" height="37">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
<input type="text" name="yourname" size="30">
</font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><b><font face="Franklin Gothic Book"><b><font size="3" face="Gill Sans MT">Your
Email</font></b></font></b></font></div>
</td>
<td width="335" height="37">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
</font><font size="3">
<input type="text" name="youremail" size="30" value="youremail@domain.com">
</font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><b><font size="3" face="Gill Sans MT">Your
Site Name </font></b></font></div>
</td>
<td width="335" height="37">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font size="3">
</font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
</font><font size="3">
<input type="text" name="yoursite" size="30">
</font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><b><font size="3" face="Gill Sans MT">Your
URL</font></b></font></div>
</td>
<td width="335" height="35">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font size="3">
</font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
</font><font size="3">
<input type="text" name="yoururl" size="30" value="http://">
</font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center">
<p><font face="Franklin Gothic Book"><b><font face="Gill Sans MT">Your
Number</font></b></font></p>
</div>
</td>
<td width="335" height="37">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
</font><font size="3">
<select name="yournumber">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select>
</font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font></font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><b><font size="3" face="Gill Sans MT">Coordinates</font></b></font></div>
</td>
<td width="335" height="37">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
</font><font size="3">
<input type="text" name="coordinates" size="20" value=" i.e. A-1 or A.B-1 or A-1.2">
</font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><b><font size="3" face="Gill Sans MT">Your
Image</font><font size="3"><font size="1"><br>
</font></font></b><font size="3"><font size="1" face="Verdana">gif -
png - jpg / jpeg files </font></font></font></div>
</td>
<td width="335" height="37">
<div align="center"><font size="3">
<input type="file" name="image1" size="30" value="">
<font face="Franklin Gothic Book" size="1" color="#999999"> </font></font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Franklin Gothic Book"><b><font size="3" face="Gill Sans MT">Your
Snapshot</font><font size="3"><font size="1"><br>
</font></font></b><font size="3"><font size="1"><font face="Franklin Gothic Book"><font size="3"><font size="1" face="Verdana">jpg
/ jpeg files </font></font></font></font></font></font></div>
</td>
<td width="335" height="37">
<div align="center"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"></font></font><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font></font></font><font size="3">
</font><font size="3">
<input type="file" name="file2" size="30" value="">
</font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Gill Sans MT"><b>pop-up message description</b></font></div>
</td>
<td width="335" height="37">
<div align="center"><font size="3">
<input type="text" name="popupmessage" size="40" value="Site description -- 60 characters max." maxlength="60">
</font></div>
</td>
</tr>
<tr>
<td width="248" height="37">
<div align="center"><font face="Gill Sans MT"><b>pop-up message<font size="3">
color BG</font></b></font></div>
</td>
<td width="335" height="37">
<div align="center"><font size="3">
<select name="popupcolors">
<option selected>yellow hue</option>
<option>blue hue</option>
<option>red hue</option>
<option>green hue</option>
<option>orange hue</option>
<option>pink tint</option>
<option>purple hue</option>
<option>brown hue</option>
<option>beige tint</option>
<option>gray shade</option>
<option>plain white</option>
</select>
</font></div>
</td>
</tr>
</table>
<hr>
<div align="left">
<p>
<input type="checkbox" value="checkbox" name="checkthisbox">
Check this box.<font color="#FF0000" size="2">*</font></p>
<p align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="clear" value="Reset">
</p>
<p><font face="Franklin Gothic Book"><font face="Franklin Gothic Book"><font color="#FF0000" size="1">*</font></font></font>
<font size="1" face="Trebuchet MS">required fields</font></p>
</div>
<div align="center">
<hr>
<p>&nbsp; </p>
</div>
</form>
<p>&nbsp; </p>
</body>
</html></font><div align="center">
</div>

Thank you in advance.
SL999.</div>
<!-- / message -->

Comments

Sign In or Register to comment.