Looking for php mail form w/ attachments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sithlord999
    New Member
    • Aug 2006
    • 1

    #1

    Looking for php mail form w/ attachments

    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($submi t)) {
    //check for email injection attack; refuse if injection
    $attack = false;
    foreach($_POST as $field => $input) {
    $input = stripslashes($i nput);
    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.co m";

    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)



    here's the Dreamweaver html code for my form:

    --------------------------------------------------------------------------------------------------------------------
    <html>
    <head>
    <title>Submissi on Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFF F" text="#000000">
    <form name="submissio n" method="post" action="" enctype="multip art/form-data">
    <p align="center"> <font size="6" face="Gill Sans MT"><b>Submissi on Form</b></font></p>
    <table width="589" border="1" cellspacing="0" cellpadding="0" height="111" bgcolor="#99999 9" bordercolor="#F FFFFF">
    <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="youremai l@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="yournumbe r">
    <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="coordinat es" 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="popupmess age" 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="popupcolo rs">
    <option selected>yellow hue</option>
    <option>blue hue</option>
    <option>red hue</option>
    <option>green hue</option>
    <option>orang e hue</option>
    <option>pink tint</option>
    <option>purpl e 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="checkthis box">
    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.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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:

    Comment

    Working...