By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,956 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,956 IT Pros & Developers. It's quick & easy.

Looking for php mail form w/ attachments

P: 1
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:
<html>
<head></head>
<body>
<?
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 = "me@mail.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>

--------------------------------------------------------------------------------------------------------------------

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)
http://66.102.7.104/search?q=cache:...us&ct=clnk&cd=4


here's the Dreamweaver html code for my form:

--------------------------------------------------------------------------------------------------------------------
<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>
--------------------------------------------------------------------------------------------------------------------

Thank you in advance.
SL999.
Aug 11 '06 #1
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
If you want to write everything yourself, that's fine. But I would suggest that you have a look at the various email classes available at www.phpclasses.org, e.g. the libMail class at link http://www.phpclasses.org/browse/package/1458.html

Excerpts from the description:
This is class is an enhanced version of Leo West libMail.

The class has some improvements setting recipients with To, CC, BCC, setting the return path address and attaching files to the message

The class also provides some anti-spamming precautions by setting some headers that identify the IP address of the machine of the user accessing the current script page.
Ronald :cool:
Aug 11 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.