PHP email form with attachments?

123457

Comments

  • edited April 2011
    Lincoln wrote:
    "new" is a keyword for instantiating classes... that's the error killing your script. All you need is the word "array" there. I'm also not sure that substr can handle arrays as input anyway... I don't see anything in the documentation about it.

    You want the pathinfo function.

    [php]
    $path = pathinfo($_FILES);
    if($path!="jpg" && $path!="gif" && $path!="png") {
    //unlink, die
    }
    [/php]As an aside, I also recommend either allowing or converting "jpeg" since sometimes that crops up as an alternate jpg extension.

    The posts on emails with attachments has saved my bacon! Thanks so much to everyone for adding to the original code.

    I'm struggling to implement this file type check and can't figure out what I'm doing wrong. I've tried playing around with it but my php isn't up to much so could really do with some help.

    Can anyone out there explain to me where I add it, and if there's anything else i need to do to make it work?

    If I add it and put the die in there, it kills any form type even if it's allowed, if I don't put it in it allows everything as you'd expect.

    Been trying to solve this all afternoon and not getting anywhere fast...

    I'll be eternally greatful for any help!
  • edited May 2011
    I've been able to successfully upload multiple files using either some of the code used in this thread, or phpmailer-fe. I have no idea which files are from which fields though.

    If for example you have 4 fields in your form where an upload can be inserted.

    Field 1: [Browse for file]
    Field 2: [Browse for file]
    Field 3: [Browse for file]
    Field 4: [Browse for file]

    and the user were to upload example.txt to field 2, and image.jpg to field 3.
    In the email, all I'm getting is the two attachments example.txt and image.jpg, with the body text:

    Field 1:
    Field 2:
    Field 3:
    Field 4:

    How do I have it insert the corresponding file names?
  • edited May 2011
    [php]
    $message .= "<table border='0' cellpadding='5' cellspacing='0'>";
    $message .= "<tr valign='top'><td>LAN ID</td><td>Workstation</td><td>Application ID</td><td>Account Example</td></tr>";
    $message .= "<tr valign='top'><td>" . $lan1 . "</td><td>" . $workstation1 . "</td><td>" . $appid1 . "</td><td>" . $account1 . "</td></tr>";
    [/php]This works perfectly for me and I have to thank you and everyone here for figuring this all out


    For some reason I can't get html messages to display properly. Looking at the source code I receive in the email, it chews up the 2 characters that come after an = sign. For example, if my code was similar to the above, it would come through as
    [html]
    <table border=' cellpadding=' cellspacing='>
    <tr valign=op'><td>LAN ID</td>...
    [/html]

    I've also tried setting the $body message in a number of different ways to get this working.
    Is Mat the only one that has sent the message in html successfully?

    Although ideally I would like to get filenames in the body (before I worry about prettying it up), I'm just hoping someone could provide some insight on this issue.
  • edited May 2011
    struddysit wrote:
    For some reason I can't get html messages to display properly. Looking at the source code I receive in the email, it chews up the 2 characters that come after an = sign.

    For some reason, commenting out [php]$message .= "Content-Transfer-Encoding: quoted-printable\n"; [/php]<code style="white-space: nowrap;"><code>
    seems to allow the email to come through OK with a html message and the attachment.
    </code></code>
  • edited May 2011
    struddysit wrote:
    How do I have it insert the corresponding file names?

    Worked it out, [php]$field1=$_FILES;[/php]
  • edited May 2011
    Kwitko wrote:
    As promised. Now I didn't add any error checking or formatting. My goal was simply to make sure the MIME encoding was done right. MIME headers are *very* finicky. If you want to add more attachments, you could foreach or while the chunk routine.

    Without further ado, I give you:

    [php]


    //EDIT: added some additional comments. I realized after posting that it's kind of silly to add the MIME boundary if you're not neccessarily sending an attachment, so the encoding routine plus the boundaries for the attachment should really be conditional. Then again, the whole purpose of this script is so you can send attachments, right?


    I think this script is really useful, thank you so much for posting! However can i get further help, based on this php script, that is, if i wanted to set:

    1. i can only send the attachment to one 'selected' email, let says you@domain.com so any attachments will direct to that chosen email when clicking the submit button

    2. the file type is limited to pdf and jpg only, and nothing else

    3. the file size is set to a maximum of 1000 kb only or error message appears

    Can anyone help me to modify the script based on these requirements? Your help is very much appreciated.

    Thank you.


    (this is the code)
    <?php

    function sendMail() {
    <FORM name=send action="[COLOR=method=post encType=multipart/form-data #0000bb?><FONT face=]Oops! You forgot to fill out the email address! Click on the back arrow to go back
    ");
    }
    else {
    $to_name = stripslashes($_POST/COLOR][COLOR=#dd0000]'to_name'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700);
    $from_name = stripslashes($_POST/COLOR][COLOR=#dd0000]'from_name'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700);
    $subject = stripslashes($_POST/COLOR][COLOR=#dd0000]'subject'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700);
    $body = stripslashes($_POST/COLOR][COLOR=#dd0000]'body'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700);
    $to_email = $_POST/COLOR][COLOR=#dd0000]'to_email'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700;
    $attachment = $_FILES/COLOR][COLOR=#dd0000]'attachment'[/COLOR][COLOR=#007700/COLOR][COLOR=#dd0000]'tmp_name'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700;
    $attachment_name = $_FILES/COLOR][COLOR=#dd0000]'attachment'[/COLOR][COLOR=#007700/COLOR][COLOR=#dd0000]'name'[/COLOR][/FONT][FONT=Courier New][COLOR=#007700;
    if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $fp = fopen($attachment, "rb"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    }
    //Let's start our headers
    $headers = "From: $from_name<" . $_POST/COLOR][COLOR=#dd0000]'from_email'[/COLOR][COLOR=#007700 . ">\n";
    $headers .= "Reply-To: <" . $_POST/COLOR][COLOR=#dd0000]'from_email'[/COLOR][COLOR=#007700 . ">\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
    $headers .= "X-Sender: $from_name<" . $_POST/COLOR][COLOR=#dd0000]'from_email'[/COLOR][COLOR=#007700 . ">\n";
    $headers .= "X-Mailer: PHP4\n";
    $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
    $headers .= "Return-Path: <" . $_POST/COLOR][COLOR=#dd0000]'from_email'[/COLOR][COLOR=#007700 . ">\n";
    $headers .= "This is a multi-part message in MIME format.\n";
    $headers .= "
    =MIME_BOUNDRY_main_message \n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";

    $message = "
    =MIME_BOUNDRY_message_parts\n";
    $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: quoted-printable\n";
    $message .= "\n";
    /* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
    $message .= "$body\n";
    $message .= "\n";
    $message .= "
    =MIME_BOUNDRY_message_parts--\n";
    $message .= "\n";
    $message .= "
    =MIME_BOUNDRY_main_message\n";
    $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name . "\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n";
    $message .= $data; //The base64 encoded message
    $message .= "\n";
    $message .= "
    =MIME_BOUNDRY_main_message--\n";

    // send the message
    mail("$to_name<$to_email>", $subject, $message, $headers);
    print "Mail sent. Thank you for using the MyNewName5333 Mailer.";
    }
    }

    ?>


    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;


    ****** http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    *******="css" type="text/css">
    <!--
    body {
    margin: 0px;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    }
    a {color: #0000ff}
    -->
    </STYLE>



    <?php
    switch ($action) {
    case "send":
    sendMail();
    showForm();
    break;
    default:
    showForm();
    }
    ?>


    <!-- php buffer end -->

    </FORM>
    [/COLOR]
  • edited May 2011
    any experts can help out here? thanks.
  • edited May 2011
    tlhung wrote:
    any experts can help out here? thanks.

    I'm no expert, but I think all the answers exist in this thread. Let's get started:

    tlhung wrote:
    1. i can only send the attachment to one 'selected' email, let says you@domain.com so any attachments will direct to that chosen email when clicking the submit button

    I think for this you'd just want to change the $to_name line:
    $to_name = you@domain.com;

    tlhung wrote:
    2. the file type is limited to pdf and jpg only, and nothing else

    [PHP]
    // check for valid file types
    $allowedExtensions = array("pdf","jpg","jpeg");
    foreach ($_FILES as $file) {
    if ($file > '') {
    if (!in_array(end(explode(".",
    strtolower($file))),
    $allowedExtensions)) {
    die($file.' is an invalid file type!<br/>'.
    '<a href="javascript:history.go(-1);">'.
    '<&lt Go Back</a>');
    }
    }
    } [/PHP]

    tlhung wrote:
    3. the file size is set to a maximum of 1000 kb only or error message appears

    I'm not sure about this one, but I do think other people in this thread have posted solutions.
  • edited May 2011
    Thanks Struddysit, i think your help is useful, i haven't try yet since i do not have a terminal to try it out during the weekend, but i will in few days time. By the way, can you be a little more specific, in which part of the script should i fill in your php suggested?

    struddysit wrote:
    I'm no expert, but I think all the answers exist in this thread. Let's get started:




    I think for this you'd just want to change the $to_name line:
    $to_name = you@domain.com;




    [php]
    // check for valid file types
    $allowedExtensions = array("pdf","jpg","jpeg");
    foreach ($_FILES as $file) {
    if ($file > '') {
    if (!in_array(end(explode(".",
    strtolower($file))),
    $allowedExtensions)) {
    die($file.' is an invalid file type!
    '.
    ''.
    '<&lt Go Back');
    }
    }
    } [/php]




    I'm not sure about this one, but I do think other people in this thread have posted solutions.
  • edited June 2011
    It is working! TY so much struddysit.

    There is this section which i need to get further help, if anyone could help. That is the last section where if the email is successfully sent, a message of 'Thank you for using MyNewName5333 Mailer' appears. Instead of making a message like that appear, could we make the page forward to let says 'thankyou_page.html' upon clicking the send?

    At the moment, i think we need to change the section written below:

    print "Mail sent. Thank you for using the MyNewName5333 Mailer.";

    Thank you
  • TushonTushon I'm scared, Coach Alexandria, VA Icrontian
    edited June 2011
    tlhung wrote:
    It is working! TY so much struddysit.

    There is this section which i need to get further help, if anyone could help. That is the last section where if the email is successfully sent, a message of 'Thank you for using MyNewName5333 Mailer' appears. Instead of making a message like that appear, could we make the page forward to let says 'thankyou_page.html' upon clicking the send?

    At the moment, i think we need to change the section written below:

    print "Mail sent. Thank you for using the MyNewName5333 Mailer.";

    Thank you
    Perhaps this source? <-- not a PHP or any sort of coding expert, just a random google with what you needed. Something within the code was breaking (probably a failsafe by forums to prevent clickjacking/etc)
  • edited June 2011
    Hi, I am very new to php. I was trying to send email through php and your code looks excellent. However, none of my mails are actually sent although I am getting a sent mail message. I presume I have to configure php to talk to smtp. But how? Here is how my php.ini looks:

    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    SMTP = localhost
    ; http://php.net/smtp-port
    smtp_port = 25

    ; For Win32 only.
    ; http://php.net/sendmail-from
    ;sendmail_from = me@localhost.com

    Thanks in advance
  • edited July 2011
    Hi Guys,
    I found this topic yesterday through google, very informative and great bit of code so thanks to the original author.
    It worked great in a test page so I did a little bit of tweaking and then copied the code over to a wordpress template, but now it doesnt seem to work. Can someone take a look at this for me?

    I have pasted the WHOLE content of the page template which can be found here. Apologies for the length of the post.

    Edit: Sorry but I cant get the big load of code to display right in this post so i'm sorry to have to ask you but could you go to the page and view the source that way. Apologies.
  • MiracleManSMiracleManS Chambersburg, PA Icrontian
    edited July 2011
    adejones wrote:
    Hi Guys,
    I found this topic yesterday through google, very informative and great bit of code so thanks to the original author.
    It worked great in a test page so I did a little bit of tweaking and then copied the code over to a wordpress template, but now it doesnt seem to work. Can someone take a look at this for me?

    I have pasted the WHOLE content of the page template which can be found here. Apologies for the length of the post.

    Edit: Sorry but I cant get the big load of code to display right in this post so i'm sorry to have to ask you but could you go to the page and view the source that way. Apologies.


    adejones, we're not going to be able to view the code source on that because php is server side. The only thing we'll see is the rendered HTML.
  • edited July 2011
    Right, just done a couple of tests, and the form DOES work... as you can see if you fill out my test form here... http://www.primarycarecommunity.net/formtest.php

    BUT then I copy the exact same code over to my wordpress page template, thats when it no longer works.

    Would you know anything about this?

    The code from formtest.php is:

    <!--?php
    [php]








    [/php]-->
  • TushonTushon I'm scared, Coach Alexandria, VA Icrontian
    edited July 2011
    pastebin.com, perhaps or wrap your stuff there in [code]
  • edited July 2011
    Tushon wrote:
    pastebin.com, perhaps or wrap your stuff there in [code]

    working form in its own .php - http://pastebin.com/PYizPV9U
    Not working form in wordpress page template - http://pastebin.com/QgfRxiXU
  • TushonTushon I'm scared, Coach Alexandria, VA Icrontian
    edited July 2011
    Now one of those smarty web dev types should be able to give it a glance and see what is going on.
  • MiracleManSMiracleManS Chambersburg, PA Icrontian
    edited July 2011
    Lincoln or Jared should be able to give you a good idea. I'll give 'em a ping. Although Jared is your best bet, since I think Linc is on vacay.

    As a quick guess without taking a detailed look, it'd be important to not use any variables set in wordpress include files (which would be just about anything to do with design). If no one else replies, I'll take a look in the morning.
  • edited July 2011
    Right, there's a bit of progress.
    The form now works with wordpress, see code - http://pastebin.com/mFH7hLPm
    However, when I change:
    print "Mail sent. Thank you for using the Mailer.";
    to:
    header("Location: http://primarycarecommunity.net/success");

    (Because I dont just want the thank you message to display, I want my form to redirect me to a success page)
    I get the following message appear where the previous thank you message appeared:

    Warning: Cannot modify header information - headers already sent by (output started at /home/adejones/public_html/wp-content/themes/pcc/jobs.php:112) in /home/adejones/public_html/wp-content/themes/pcc/jobs.php on line 106

    line 106 is the header("Location: http://primarycarecommunity.net/success");
    and line 112 is <html <?php language_attributes(); ?>>
  • edited July 2011
    Sorted :-) I followed this from another site following a google search.

    Using output buffering is a good way to ensure that no output gets in the way of sending headers, cookies, etc. At the beginning of the script, put

    <?php
    ob_start()
    ?>, and at the end, put
    <?php
    ob_end_flush();
    ?>
    <!-- / message -->
  • edited July 2011
    last problem, i promise...

    on validation, if the wrong file type is attached, the message appears to say so, but then anything under that doesnt load. I think the die command stops the rest of the page loading.
    Can I get this to redirect to an error page?
    If so, how do I amend this bit of code...

    thanks

    [php]// check for valid file types
    if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $allowedExtensions = array("doc","docx","txt");
    foreach ($_FILES as $file) {
    if ($file > '') {
    if (!in_array(end(explode(".",
    strtolower($file))),
    $allowedExtensions)) {
    die($file.' is an invalid file type!
    '.
    ''.
    '<&lt Go Back');

    }else{
    $fp = fopen($attachment, "rb"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    }
    }
    }
    }
    [/php]
  • edited August 2011
    Kwitko wrote:
    Fill me in on what you need.

    Hi Kwitko,

    What i need is an urgent PHP script that will allow people to upload their CV (.pdf, .doc, .docx, .txt and .rtf) and this be emailed to me as an email attachment.

    i have created a form and this can be found on the following link:

    http://www.heritagesolicitors.com/Careers.html

    The email this will be sent to is contactform@heritagesolicitors.com

    Please let me know what you can do :)

    My email address is m4_yas@hotmail.co.uk

    Thanks. I await your urgent reply.

    Yas
  • edited September 2011
    Hi Guys,

    The original script seems to work.
    Well most of the scripts I try seem to work in some fashion.

    However, when I receive the email, it is blank?
    No matter which one I try, they are all blank?
    All the Subject and reply lines are working just zero content in the email.

    Any Ideas on what I'm doing wrong?

    Tom
  • edited September 2011
    Here is my html, I'm trying to customise a template.

    [HTML]<!DOCTYPE html>
    <html>
    <head>

    <title>
    Digedi Submission Form
    </title>

    <!-- Meta Tags -->
    ****** charset="utf-8">
    ****** name="generator" content="digedi.com.au" />

    <!-- CSS -->
    <link rel="stylesheet" href="css/structure.css" type="text/css" />
    <link rel="stylesheet" href="css/form.css" type="text/css" />

    <!-- JavaScript -->
    ******** src="scripts/wufoo.js"></script>

    <!--[if lt IE 10]>
    ******** src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script&gt;
    <![endif]-->
    </head>

    <body id="public">
    <div id="container" class="ltr">



    <form id="form2" name="form2" class="wufoo topLabel page" autocomplete="off" enctype="multipart/form-data" method="post" novalidate
    action="contact.php">

    <header id="header" class="info">
    <h2>Digedi Submission Form</h2>
    <div>Please fill out your details below</div>
    </header>

    <ul>

    <li id="foli318" class=" ">
    <label class="desc" id="title318" for="Field318">
    Name
    <span id="req_318" class="req">*</span>
    </label>
    <span>
    <input id="firstname" name="firstname" type="text" class="field text fn" value="" size="8" tabindex="1" required />
    <label for="Field318">First</label>
    </span>
    <span>
    <input id="lastname" name="lastname" type="text" class="field text ln" value="" size="14" tabindex="2" required />
    <label for="Field319">Last</label>
    </span>
    <p class="instruct" id="instruct318"><small>Please enter your first and last name</small></p>
    </li>
    <li id="foli6" class=" ">
    <label class="desc" id="title6" for="Field6">
    Business name
    <span id="req_6" class="req">*</span>
    </label>
    <div>
    <input id="Field6" name="Field6" type="text" class="field text medium" value="" maxlength="255" tabindex="3" onKeyUp="" required />
    </div>
    <p class="instruct" id="instruct6"><small>Please enter the name of the business</small></p>
    </li><li id="foli2" class=" ">
    <label class="desc" id="title2" for="Field2">
    Position
    <span id="req_2" class="req">*</span>
    </label>
    <div>
    <input id="Field2" name="Field2" type="text" class="field text medium" value="" maxlength="255" tabindex="4" onKeyUp="" required />
    </div>
    <p class="instruct" id="instruct2"><small>Please enter your position at the business</small></p>
    </li><li id="foli323" class=" ">
    <label class="desc" id="title323" for="Field323">
    Email
    <span id="req_323" class="req">*</span>
    </label>
    <div>
    <input id="email" name="email" type="email" spellcheck="false" class="field text medium" value="" maxlength="255" tabindex="5" required />
    </div>
    <p class="instruct" id="instruct323"><small>Please enter your email address</small></p>
    </li>
    <li id="foli321" class=" ">
    <label class="desc" id="title321" for="Field321">
    Website address
    </label>
    <div>
    <input id="Field321" name="Field321" type="url" class="field text medium" value="" maxlength="255" tabindex="6" />
    </div>
    <p class="instruct" id="instruct321"><small>If you currently have a website please enter the address</small></p>
    </li><li id="foli8" class="complex ">
    <label class="desc" id="title8" for="Field8">
    Address
    <span id="req_8" class="req">*</span>
    </label>
    <div>
    <span class="full addr1">
    <input id="Field8" name="Field8" type="text" class="field text addr" value="" tabindex="7" required />
    <label for="Field8">Street Address</label>
    </span>
    <span class="full addr2">
    <input id="Field9" name="Field9" type="text" class="field text addr" value="" tabindex="8" />
    <label for="Field9">Address Line 2</label>
    </span>
    <span class="left city">
    <input id="Field10" name="Field10" type="text" class="field text addr" value="" tabindex="9" required />
    <label for="Field10">City</label>
    </span>
    <span class="right state">
    <input id="Field11" name="Field11" type="text" class="field text addr" value="" tabindex="10" required />
    <label for="Field11">State / Province / Region</label>
    </span>
    <span class="left zip">
    <input id="Field12" name="Field12" type="text" class="field text addr" value="" maxlength="15" tabindex="11" required />
    <label for="Field12">Postal / Zip Code</label>
    </span>
    <span class="right country">
    <select id="Field13" name="Field13" class="field select addr" tabindex="12" >
    <option value="" ></option>
    <option value="Australia" selected="selected">Australia</option>
    </select>
    <label for="Field13">Country</label>
    </span>
    </div>
    <p class="complex instruct" id="instruct8"><small>Please enter the business address</small></p>
    </li>
    <li id="foli216" class=" notStacked ">
    <fieldset>
    <![if !IE | (gte IE 8)]>
    <legend id="title216" class="desc">
    Which of the following industries can you provide goods/services to?
    <span id="req_216" class="req">*</span>
    </legend>
    <![endif]>
    <!--[if lt IE 8]>
    <label id="title216" class="desc">
    Which of the following industries can you provide goods/services to?
    <span id="req_216" class="req">*</span>
    </label>
    <![endif]-->
    <div>
    <span>
    <input id="Field216" name="Field216" type="checkbox" class="field checkbox" value="Mining/Resources" tabindex="13" />
    <label class="choice" for="Field216">Mining/Resources</label>
    </span>
    <span>
    <input id="Field217" name="Field217" type="checkbox" class="field checkbox" value="Construction" tabindex="14" />
    <label class="choice" for="Field217">Construction</label>
    </span>
    </div>
    </fieldset>
    <p class="instruct" id="instruct216"><small>Check both if required</small></p>
    </li><li id="foli324" class=" notStacked ">
    <fieldset>
    <![if !IE | (gte IE 8)]>
    <legend id="title324" class="desc">
    What region can you provide your services?
    <span id="req_324" class="req">*</span>
    </legend>
    <![endif]>
    <!--[if lt IE 8]>
    <label id="title324" class="desc">
    What region can you provide your services?
    <span id="req_324" class="req">*</span>
    </label>
    <![endif]-->
    <div>
    <span>
    <input id="Field324" name="Field324" type="checkbox" class="field checkbox" value="Darwin" tabindex="15" />
    <label class="choice" for="Field324">Darwin</label>
    </span>
    <span>
    <input id="Field325" name="Field325" type="checkbox" class="field checkbox" value="Alice" tabindex="16" />
    <label class="choice" for="Field325">Alice</label>
    </span>
    <span>
    <input id="Field326" name="Field326" type="checkbox" class="field checkbox" value="Throughout Northern Territory" tabindex="17" />
    <label class="choice" for="Field326">Throughout Northern Territory</label>
    </span>
    </div>
    </fieldset>
    <p class="instruct" id="instruct324"><small>Check multiples if required</small></p>
    </li><li id="foli525"
    class=" "><label class="desc" id="title525" for="Field525">
    If the region are not listed please list below
    </label>

    <div>
    <textarea id="Field525"
    name="Field525"
    class="field textarea small"
    spellcheck="true"
    rows="10" cols="50"
    tabindex="18"
    onkeyup=""
    ></textarea>

    </div>
    </li>

    <li id="foli12" class="altInstruct " >
    <label class="desc" id="title12" for="Field12">
    Please upload your logo or images you would like to include
    </label>
    <div>
    <input id="attachment" name="attachment" type="file" class="field file" size="12" tabindex="8" />
    </div>
    <p class="instruct" id="instruct12"><small>The following file formats only: .JPG, .jpeg, .pdf, .zip (2 MB max) </small></p>
    </li>

    <li id="foli626"
    class=" "><label class="desc" id="title626" for="Field626">
    In 100 words or less, please provide a breif overview of your business including a list of the goods and/or services you can provide (relevant to the Resources and Construction industry) and any relevant experience (if applicable)
    </label>

    <div>
    <textarea id="Field626"
    name="Field626"
    class="field textarea large"
    spellcheck="true"
    rows="10" cols="50"
    tabindex="19"
    onkeyup=""
    ></textarea>

    </div>
    </li> <li class="buttons ">
    <div>

    <input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="Submit"
    /></div>
    </li>

    <li class="hide">
    <label for="comment">Do Not Fill This Out</label>
    <textarea name="comment" id="comment" rows="1" cols="1"></textarea>
    <input type="hidden" id="idstamp" name="idstamp" value="LTH7XxgVsg0oaKgXxoSqNfUlcIvKe3ZLx5jfppWRdCg=" />
    </li>
    </ul>
    </form>

    </div><!--container-->
    <img id="bottom" src="images/bottom.png" alt="" />

    <a class="powertiny" href="http://wufoo.com/tour/&quot; title="Powered by Wufoo"
    style="display:block !important;visibility:visible !important;text-indent:0 !important;position:relative !important;height:auto !important;width:95px !important;overflow:visible !important;text-decoration:none;cursor:pointer !important;margin:0 auto !important">
    <span style="background:url(./images/powerlogo.png) no-repeat center 7px; margin:0 auto;display:inline-block !important;visibility:visible !important;text-indent:-9000px !important;position:static !important;overflow: auto !important;width:62px !important;height:30px !important"></span>
    <b style="display:block !important;visibility:visible !important;text-indent:0 !important;position:static !important;height:auto !important;width:auto !important;overflow: auto !important;font-weight:normal;font-size:9px;color:#777;padding:0 0 0 3px;"></b>
    </a>
    </body>
    </html>[/HTML]

    And here is my contact.php

    [PHP]<?php
    // $to_name = stripslashes($_POST);
    $from_name = stripslashes($_POST);
    $subject = "Contact Us";
    // $body = stripslashes($_POST);
    $firstname = stripslashes($_POST);
    $lastname = stripslashes($_POST);
    $to_email = 'tom@mitara.com.au';
    $email = $_POST;
    $attachment = $_FILES;
    $attachment_name = $_FILES;
    if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $fp = fopen($attachment, "rb"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    }
    //Let's start our headers
    $headers = "From: $from_name<" . $_POST . ">\n";
    $headers .= "Reply-To: <" . $_POST . ">\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
    $headers .= "X-Sender: $from_name<" . $_POST . ">\n";
    $headers .= "X-Mailer: PHP4\n";
    $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
    $headers .= "Return-Path: <" . $_POST . ">\n";
    $headers .= "This is a multi-part message in MIME format.\n";
    $headers .= "
    =MIME_BOUNDRY_main_message \n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";

    $message = "
    =MIME_BOUNDRY_message_parts\n";
    $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: quoted-printable\n";
    $message .= "\n";
    /* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
    $message = "$firstname\n $lastname\n $email\n";
    $message .= "\n";
    $message .= "
    =MIME_BOUNDRY_message_parts--\n";
    $message .= "\n";
    $message .= "
    =MIME_BOUNDRY_main_message\n";
    $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name . "\"\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n";
    $message .= $data; //The base64 encoded message
    $message .= "\n";
    $message .= "
    =MIME_BOUNDRY_main_message--\n";

    $sent = @mail(&quot;$from_name <$to_email>", $subject, $message, $headers);

    // send the message
    // mail("$from_name <$to_email>", $subject, $message, $headers);

    if($sent)
    {print "Mail sent. Thank you for using the MyNewName5333 Mailer.";}
    else
    {print "We encountered an error sending your mail";}

    ?>[/PHP]


    Now I have tried simpler php code, with just plain text and its work fine.
    Now that I have added the attachment functionality all I get is blank. :confused::confused::confused:
  • edited September 2011
    I'm only trying with a few fields at first, to try and get it working....
  • Straight_ManStraight_Man Geeky, in my own way Naples, FL Icrontian
    edited September 2011
    Try with newer Thunderbird as email client. It may be the email client does not know how to recognize mixed conttent email and show it all in text reading mode and/or run the html content.

    Even Thunderbird likes plain-text email displaying over part-text (header and/or PGP signature, for example) than html code. You need something that parses both content types. If your code strips html before displaying messages for security, only the textual part will show and it will show only in an account set for text-only. Testing with a client with one account set up for text-only and one account set up as defaulted to html email (mixed content) will let you test your code.

    Some clients also default to text-only email or have options that allow account to be text-only, recent Thunderbird has this option also(by account), so you can use it to bench test your code. Servers that for seurity strip html code from email or reformat it to plain text will leave folks who want their email displayed in html mad-- no content that is not text will show. Problem may be with email client and/or account settings.
  • KwitkoKwitko Sheriff of Banning (Retired) By the thing near the stuff Icrontian
    edited September 2011
    UM, the email client shouldn't matter. You can try adding output along the way to see where the failure occurs.

    For example, in this section, comment out the fopen part.
    [php] if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    $fp = fopen($attachment, "rb"); //Open it
    $data = fread($fp, filesize($attachment)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);
    } [/php][php] if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
    echo "file uploaded";
    // $fp = fopen($attachment, "rb"); //Open it
    //$data = fread($fp, filesize($attachment)); //Read it
    //$data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    //fclose($fp);
    }
    else {
    echo "nope!";
    } [/php]This way you're checking if the outcome for the if statement = 1, rather than zero. If nothing comes up, the problem lies elsewhere.
  • Straight_ManStraight_Man Geeky, in my own way Naples, FL Icrontian
    edited September 2011
    One other thing-- look and see if your script that is apparently sending contentless email has the mis-spelling BOUNDRY in it yet. Change BOUNDRY to BOUNDARY. See if that helps.
  • KwitkoKwitko Sheriff of Banning (Retired) By the thing near the stuff Icrontian
    edited September 2011
    That shouldn't matter. As long as boundary= is spelled correctly and it's consistent across each boundary.
Sign In or Register to comment.