Results 1 to 4 of 4

Thread: Help with image upload and email attachment

  1. #1
    Join Date
    Sep 2013

    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:
    //include the header and set the title
    define('TITLE''Online Estimate Form');

    //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 {
    '<p class="error">Please select a title for yourself</p>';
    $okay TRUE;
        if (empty(
    $fname)) {
    '<p class="error">Please enter your first name</p>';
    $okay TRUE;
        if (empty(
    $lname)) {
    '<p class="error">Please enter your last name</p>';
    $okay TRUE;
        if (empty(
    $phone)) {
    '<p class="error">Please enter phone number</p>';
    $okay TRUE;
        if (empty(
    $email)) {
    '<p class="error">Please enter your email address</p>';
    $okay TRUE;
        if (empty(
    $make)) {
    '<p class="error">Please enter the make of your vehicle</p>';
    $okay TRUE;
        if (empty(
    $model)) {
    '<p class="error">Please enter the model of your vehicle</p>';
    $okay TRUE;
        if (empty(
    $year)) {
    '<p class="error">Please enter the year of your vehicle</p>';
    $okay TRUE;
        if (empty(
    $vin)) {
    '<p class="error">Please enter the 17 digit VIN for your vehicle</p>';
    $okay TRUE;
        if (empty(
    '<p class="error">Please enter the mileage of your vehicle</p>';
    $okay TRUE;
        if (empty(
    $tag)) {
    '<p class="error">Please enter the tag number of your vehicle</p>';
    $okay TRUE;
        if (empty(
    $description)) {
    '<p class="error">Please the required description of damage to your vehicle</p>';
    $okay TRUE;
    $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>";
    "<p> You will been contact by someone within our office within 3 business days about the estimate for repairs.</p>";
    '<p>If you have any question or concerns please feel free to contact us at 803.794.8351.</p>';
    '<p>Thank you for your business!</p>';
    '<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
                    The vin is 
    $vin, mileage $mileage, tag number $tag.\n
                    They can be reached by phone at 
    $phone, or by email at $email.";
    //Clear the post items
    $_POST = array();
        } else {
    '<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>
            <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>

    Last edited by NogDog; 09-20-2013 at 12:06 PM. Reason: added [php] tags

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

    <title>ShotDev.Com Tutorial</title>
    <form action="php_sendmail_upload2.php" method="post" name="form1" enctype="multipart/form-data">
    <table width="343" border="1">
    <td><input name="txtTo" type="text" id="txtTo"></td>
    <td><input name="txtSubject" type="text" id="txtSubject"></td>
    <td><textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea></td>
    <td>Form Name</td>
    <td><input name="txtFormName" type="text"></td>
    <td>Form Email</td>
    <td><input name="txtFormEmail" type="text"></td>
    <td><input name="fileAttach" type="file"></td>
    <td><input type="submit" name="Submit" value="Send"></td>


    <title>ShotDev.Com Tutorial</title>
    $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 //

    echo "Mail send completed.";
    echo "Cannot send mail.";

  3. #3
    Join Date
    Sep 2013
    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
    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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.13468 seconds
  • Memory Usage 2,927KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates