Results 1 to 4 of 4

Thread: Help with mail code

  1. #1
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with mail code

    Hi All,

    Im new here and was seeking a little advise on a mail script please

    I have attached my mailform php code which works 100% if you add an attachement to it when submitting and the email is all laid out in a html table.

    The issue arises when you don't add an attachement and the email comes in just plain text and all the html is gone and only 1 field is submitted.

    Any help would be greatly appreciated.

    thanks in advanced

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You've got your message set up in the if for the file upload. Try this

    PHP Code:
    if (is_uploaded_file($fileatt)) {
      
    // Read the file to be attached ('rb' = read binary)
      
    $file fopen($fileatt,'rb');
      
    $data fread($file,filesize($fileatt));
      
    fclose($file);

      
    // Generate a boundary string
      
    $semi_rand md5(time());
      
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
      
      
    // Add the headers for a file attachment
      
    $headers .= "\nMIME-Version: 1.0\n" .
                  
    "Content-Type: multipart/mixed;\n" .
                  
    " boundary=\"{$mime_boundary}\"";
                  
    }
                   
    $message "
    Message Recieved From:  
    $name
    <br /><br />
    <table border='1' bordercolor='#3300FF' style='background-color:#CCFF66' width='50%' cellpadding='3' cellspacing='3'>
        <tr>
            <td style='background-color:yellow' colspan='2' align='center'><b>Contact Details</b></td>
            <td></td>
            <td style='background-color:yellow' colspan='4' align='center'><b>Equipment Owned</b></td>
            <td></td>
            <td></td>
            <td></td>
        <td></td>
        </tr>
        <tr>
            <td>Name</td>
            <td>
    $name</td>
            <td></td>
            <td>
    $pc</td>
            <td>
    $laptop</td>
            <td>
    $printer</td>
        <td>
    $tv</td>
        </tr>
        <tr>
            <td>Email</td>
            <td><a href='mailto:
    $email'>$email</a></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        <td></td>
        </tr>
        <tr>
            <td>Phone</td>
            <td>
    $phone</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        <td></td>
        </tr>
      <tr>
            <td>Over 18</td>
            <td>
    $group1</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        <td></td>
        </tr>
    </table>

    "
    ;

      
    // Add a multipart boundary above the plain message
      
    $message .= "This is a multi-part message in MIME format.\n\n" .
                 
    "--{$mime_boundary}\n" .
                 
    "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
                 
    "Content-Transfer-Encoding: 7bit\n\n" .
                 
    $message "\n\n";

      
    // Base64 encode the file data
      
    $data chunk_split(base64_encode($data));

      
    // Add file attachment to the message
      
    $message .= "--{$mime_boundary}\n" .
                  
    "Content-Type: {$fileatt_type};\n" .
                  
    " name=\"{$fileatt_name}\"\n" .
                  
    //"Content-Disposition: attachment;\n" .
                  //" filename=\"{$fileatt_name}\"\n" .
                  
    "Content-Transfer-Encoding: base64\n\n" .
                  
    $data "\n\n" .
                  
    "--{$mime_boundary}--\n"
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Aug 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi bluewalrus,

    I swapped all that part of the code in my original file and all I get in the email now is all the actual html code laid out for the table

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You need to adjust the headers. I'm not sure if you need a special one for the attachment though.
    Corrections to my coding/thoughts welcome.

Bookmarks

Posting Permissions

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