dare87 Posted October 22, 2008 Share Posted October 22, 2008 What would I need to add to this code to allow me to browse for an attachment and send it with the email? Thanks <?php if (!isset($_POST['submit'])) { // Show the form. echo '<form name "contact" action="" target="_self" method="post"> <table align="center" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left"><b>From:</b></td> <td align="left"><input type="text" class="required" name="name" size="20" value="" maxlength="40" /></td> </tr> <tr> <td align="left"><b>To Email:</b></td> <td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Subject:</b></td> <td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Message:</b></td> <td align="left"><textarea class="required" name="body" rows="15" cols="40">'. $body.'</textarea></td> </tr> </table> <div align="left"> <input type="submit" class="button" name="submit" value="Send Message" /></div> <input type="hidden" class="button" name="submitted" value="TRUE" /> </form>'; } else { // Validate the from email. if (!empty($_REQUEST['name'])) { $name = stripslashes($_REQUEST['name']); } // Validate the email. if (!empty($_REQUEST['email'])) { $email = $_REQUEST['email']; } // Validate Subject. if (!empty($_REQUEST['subject'])) { $subject = $_REQUEST['subject']; } // Validate Message and combat Magic Quotes. if (!empty($_REQUEST['body'])) { $body = stripslashes($_REQUEST['body']); } // If everything has a value, check the email syntax. if ($name && $email && $subject && $body) { // Validate the email syntax. list($username,$domain) = split("@",$email); if (eregi ('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $_POST['email'])) { echo "<p>The following message has been sent to $email<br><br> $body. <br /></p>"; $headers = "From: \"{$_POST['name']}\" <$email>\r\n"; $headers .= "Reply-To: {$_POST['email']}\r\n"; mail ($email, $subject, $body, $headers); } else { echo '<p><font color="red"><strong>Please enter a valid e-mail address.</strong></font></p>'; echo '<form name "contact" action="" target="_self" method="post"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left"><b>From:</b></td> <td align="left"><input type="text" class="required" name="name" size="20" value="" maxlength="40" /></td> </tr> <tr> <td align="left"><b>To Email:</b></td> <td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Subject:</b></td> <td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Message:</b></td> <td align="left"><textarea class="required" name="body" rows="15" cols="40">'. $body.'</textarea></td> </tr> </table> <div align="left"> <input type="submit" class="button" name="submit" value="Send Message" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form>'; } } else { echo '<p><font color="red"><strong>You forgot to enter one or more required fields.</strong></font></p>'; echo '<form name "contact" action="" target="_self" method="post"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left"><b>From:</b></td> <td align="left"><input type="text" class="required" name="name" size="20" value="" maxlength="40" /></td> </tr> <tr> <td align="left"><b>To Email:</b></td> <td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Subject:</b></td> <td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Message:</b></td> <td align="left"><textarea class="required" name="body" rows="15" cols="40">'. $body.'</textarea></td> </tr> </table> <div align="left"> <input type="submit" class="button" name="submit" value="Send Message" /></div> <input type="hidden" class="button" name="submitted" value="TRUE" /> </form>'; } } // End of main isset() IF. ?> Link to comment https://forums.phpfreaks.com/topic/129618-sending-attachment/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.