www.webdeveloper.com
Results 1 to 4 of 4

Thread: Help with image upload and email attachment

Hybrid View

  1. #1
    Join Date
    Sep 2013
    Posts
    2

    Help with image upload and email attachment

    I am creating an online estimate form for a body shop. I need to collect information on the customer and image of vehicle, then email this info to the business email. I have to problem collect the form info an sending in email. I just don't know how to collect the uploads images and attach them to the outgoing email. This is what I have so far.
    PHP Code:
    <?php
    //include the header and set the title
    define('TITLE''Online Estimate Form');
    include(
    'templates/est_header.html');

    //check if the form has been submitted
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        
    $okay FALSE;
        
        
    $title $_POST['title'];
        
    $fname $_POST['fname'];
        
    $lname $_POST['lname'];
        
    $phone $_POST['phone'];
        
    $email $_POST['email'];
        
    $make $_POST['make'];
        
    $model $_POST['model'];
        
    $year $_POST['year'];
        
    $vin $_POST['vin'];
        
    $mileage $_POST['mileage'];
        
    $tag $_POST['tag'];
        
    $description $_POST['description'];
        
        
    //Validate all required fields have been completed
        
    if ($title == 'Mr.') {
            
    $title_type 'Mr.';
        } elseif (
    $title == 'Mrs.') {
            
    $title_type 'Mrs.';
        } elseif (
    $title == 'Ms.') {
            
    $title_type 'Ms.';
        } else {
            print 
    '<p class="error">Please select a title for yourself</p>';
            
    $okay TRUE;
        }
        if (empty(
    $fname)) {
            print 
    '<p class="error">Please enter your first name</p>';
            
    $okay TRUE;
        }
        if (empty(
    $lname)) {
            print 
    '<p class="error">Please enter your last name</p>';
            
    $okay TRUE;
        }
        if (empty(
    $phone)) {
            print 
    '<p class="error">Please enter phone number</p>';
            
    $okay TRUE;
        }
        if (empty(
    $email)) {
            print 
    '<p class="error">Please enter your email address</p>';
            
    $okay TRUE;
        }
        if (empty(
    $make)) {
            print 
    '<p class="error">Please enter the make of your vehicle</p>';
            
    $okay TRUE;
            
        }
        if (empty(
    $model)) {
            print 
    '<p class="error">Please enter the model of your vehicle</p>';
            
    $okay TRUE;
        }
        if (empty(
    $year)) {
            print 
    '<p class="error">Please enter the year of your vehicle</p>';
            
    $okay TRUE;
        }
        if (empty(
    $vin)) {
            print 
    '<p class="error">Please enter the 17 digit VIN for your vehicle</p>';
            
    $okay TRUE;
        }
        if (empty(
    $mileage)){
            print 
    '<p class="error">Please enter the mileage of your vehicle</p>';
            
    $okay TRUE;
        }
        if (empty(
    $tag)) {
            print 
    '<p class="error">Please enter the tag number of your vehicle</p>';
            
    $okay TRUE;
        }
        if (empty(
    $description)) {
            print 
    '<p class="error">Please the required description of damage to your vehicle</p>';
            
    $okay TRUE;
        }
        if(!
    $okay) {
            
    //Print a confrimation message
            
    print "<p>Thank you $title_type $lname the information on the damage to your $year $make $model has been recieved.</p>";
            print 
    "<p> You will been contact by someone within our office within 3 business days about the estimate for repairs.</p>";
            print 
    '<p>If you have any question or concerns please feel free to contact us at 803.794.8351.</p>';
            print 
    '<p>Thank you for your business!</p>';
            print 
    '<img src="logo.png" alt="company logo" />';
            
            
    //Send the email
            
    $to  'midlandscollisioncenter@gmail.com'//. ', ';
            //$to .= 'robbiebedwell@yahoo.com';
            
    $subject "Estimate Request";
            
    $message "$title_type $fname $lname would like an estimate on repairs to their $year $make $model.\n
                They describe the damage to their vehicle as:\n
                    
    $description.\n
                    The vin is 
    $vin, mileage $mileage, tag number $tag.\n
                    They can be reached by phone at 
    $phone, or by email at $email.";
            
    mail($to,$subject,$message);
            
            
    //Clear the post items
            
    $_POST = array();
        } else {
            print 
    '<p style="color: red; font-weight: bold;">Please correct any missing information and try again!</p>';
        }
    }

    //Leave php to create the form
    ?>

    <h2>Free Online Estimate Form</h2>
    <p>Please enter the following information to submit an online estimate<br />
        <em>* Required fields</em></p>
    <form action="estimate.php" method="post">
        <p><em style="color: red; font-style: normal;">* </em>Title: <select name="title">
                <option value="Select One"></option>
                <option value="Mr.">Mr.</option>
                <option value="Mrs.">Mrs.</option>
                <option value="Ms.">Ms.</option>
            </select>
            <em>* </em>First Name: <input type="text" name="fname" size="20"/>
            <em>* </em>Last Name: <input type="text" name="lname" size="20" /></p>
        <p><em>* </em>Phone: <input type="tel" name="phone" /><em>* </em>Email: <input type="email" name="email" /></p>
        <p><em>* </em>Vehicle Make: <input type="text" name="make" size="20" />
            <em>* </em>Vehicle Model: <input type="text" name="model" size="20" />
            <em>* </em>Vehicle Year <input type="text" name="year" size="4" /></p>
        <p><em>* </em>VIN Number <input type="text" name="vin" size="17" />
            <em>* </em>Mileage: <input type="text" name="mileage" size="8" />
            <em>* </em>Tag #: <input type="text" name="tag" size="8" /><br />
            This is a 17 digit number located in the right front corner of your dash or on your vehicle registration card.</p>
        <p><em>* </em>Please describe the damage to your vehicle and circumstance which caused the damage. <br/>
            <textarea name="description" rows="10" cols="70"></textarea></p>
        <p><em>* </em>Please upload images of the damage to your vehicle. (see sidebar for tips on taking the best pictures)<br />
            <input type="file" name="image1" /><br />
        <input type="file" name="image2" /><br />
        <input type="file" name="image3" /><br />
        <input type="file" name="image4" /><br />
        <input type="file" name="image5" /></p>
        <p><input type="submit" value="Send" /></p>
    </form>

    <?php
    include('templates/footer.html');
    ?>
    Last edited by NogDog; 09-20-2013 at 12:06 PM. Reason: added [php] tags

  2. #2
    Join Date
    Sep 2013
    Posts
    221
    Try out with this one, it may help you.

    php_sendmail_upload1.php:
    <html>
    <head>
    <title>ShotDev.Com Tutorial</title>
    </head>
    <body>
    <form action="php_sendmail_upload2.php" method="post" name="form1" enctype="multipart/form-data">
    <table width="343" border="1">
    <tr>
    <td>To</td>
    <td><input name="txtTo" type="text" id="txtTo"></td>
    </tr>
    <tr>
    <td>Subject</td>
    <td><input name="txtSubject" type="text" id="txtSubject"></td>
    </tr>
    <tr>
    <td>Description</td>
    <td><textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea></td>
    </tr>
    <tr>
    <td>Form Name</td>
    <td><input name="txtFormName" type="text"></td>
    </tr>
    <tr>
    <tr>
    <td>Form Email</td>
    <td><input name="txtFormEmail" type="text"></td>
    </tr>
    <tr>
    <td>Attachment</td>
    <td><input name="fileAttach" type="file"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Send"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    php_sendmail_upload2.php:

    <html>
    <head>
    <title>ShotDev.Com Tutorial</title>
    </head>
    <body>
    <?
    $strTo = $_POST["txtTo"];
    $strSubject = $_POST["txtSubject"];
    $strMessage = nl2br($_POST["txtDescription"]);

    //*** Uniqid Session ***//
    $strSid = md5(uniqid(time()));

    $strHeader = "";
    $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";

    $strHeader .= "MIME-Version: 1.0\n";
    $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $strHeader .= "This is a multi-part message in MIME format.\n";

    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-type: text/html; charset=utf-8\n";
    $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
    $strHeader .= $strMessage."\n\n";

    //*** Attachment ***//
    if($_FILES["fileAttach"]["name"] != "")
    {
    $strFilesName = $_FILES["fileAttach"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
    $strHeader .= "Content-Transfer-Encoding: base64\n";
    $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
    $strHeader .= $strContent."\n\n";
    }

    $flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //

    if($flgSend)
    {
    echo "Mail send completed.";
    }
    else
    {
    echo "Cannot send mail.";
    }
    ?>
    </body>
    </html>

  3. #3
    Join Date
    Sep 2013
    Posts
    2
    Thank you for your help but I copied and pasted the code and created dummy pages to test and see if the code would work and then plan to integrate it into my existing code that I posted above, but the dummy pages didn't work. Because sending attach via web form is something I am not familiar with I have no idea why it is not working. Any pointers where I should start looking for the problem.

  4. #4
    Join Date
    Sep 2013
    Posts
    221
    well..according to me you have done with the validation and designing part. Now why dont you start with the mailing section.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles