Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Mailto with attachment won't work

    I have this script and it works almost fine, but the attachment won't work.

    I have a sort of helpdesk script and with this they can supply also attachments, $ticket[attachments] is the part to get the attachments within the ticket they submitted.

    Here is the code I have:
    PHP Code:
    $to "sdghsdgh@domain.nl"

    $onderwerp "Bestelling 2009-" .$ticket['id']; 

    $headers "MIME-Version: 1.0\r\n";  
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";  
    $headers .= "From:liudjh@domain.nl\r\n";  

    $headers .= "\r\nContent-Type: multipart/mixed "
    $attachment chunk_split(base64_encode(file_get_contents('$ticket[attachments]'))); 

    $headers .= "Content-Type: application/zip; name=".$ticket[attachtments]."";   
    $headers .= "Content-Transfer-Encoding: base64";   
    $headers .= "Content-Disposition: attachment"

    mail($to$onderwerp$message$headers); 
    BTW: it needs to be possible to add any kind of attachment (in the ticket it is possible to add also any kind of attachment).

    thanks for any replies.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    How your $ticket[attachtments] gets the file to be uploaded?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I suggest you look into something like phpmailer which makes attachments easy.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    How your $ticket[attachtments] gets the file to be uploaded?
    The attachment is already uploaded (its in a folder and in mysql). Here is the whole code I have:

    The to name and cc are working (it takes the email addresses from the ticket supplied.

    PHP Code:
    <?php
    $ticket
    ['dt']=date('d-m-Y'strtotime($ticket['dt']));

    if(!empty(
    $_POST['mailopdrachtWaarde']))
    {

    echo(
    "");
      
      
      
    $message "
    <html>

    <STYLE>
          
          .style17
          {
            background-color:#FFFFFF;
            color: #000000;
          }

    </STYLE>
          
          
    <body>
    <table width=\"650\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"200\"><font face=\"arial\" size=\"6\"><b>Inkoopbon</b></font><br><font face=\"arial\" size=\"2\">No: 2009-" 
    .$ticket['id'] ."<br> Datum: " .$ticket['dt'] ." </font></td>
    <td width=\"375\"><font face=\"arial\" size=\"2\"><b>Factuuradres:</b><br><b>" 
    .$ticket['factuurnaam'] ."</b><br>" .$ticket['factuuradres'] ."<br>" .$ticket['factuurpostcode'] ." " .$ticket['factuurplaats'] ."</font></td>
    <td width=\"225\" valign=\"top\"><img src=\"$ticket[factuurpics]\"></td>
    </tr>
    </table>
    <table width=\"650\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"325\"><font face=\"arial\" size=\"2\"><b>Aan:</b><br> " 
    .$ticket['leverancier'] ."<br>T.a.v. " .$ticket['contactpers1'] ."<br>" .$ticket['adres'] ."<br>" .$ticket['postcode'] ." " .$ticket['plaats'] ."<br>" .$ticket['telefoon'] ."</font></td>
    <td width=\"325\" valign=\"top\"><font face=\"arial\" size=\"2\"><b>Afleveradres:</b><br>" 
    .$ticket['aflevernaam'] ."<br>" .$ticket['afleveradres'] ."<br>" .$ticket['afleverpostcode'] ." " .$ticket['afleverplaats'] ."<br>" .$ticket['factuurtelefoon'] ." T<br>" .$ticket['factuurfax'] ." F</font></td>
    </tr>
    </table>
    <table width=\"650\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"250\"><font face=\"arial\" size=\"2\"><b>Gewenste afleverdatum:</b></font>&nbsp " 
    .$ticket['date_deliv'] ."</td>
    </tr>
    </table>
    <table width=\"650\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"250\" valign=\"top\"><font face=\"arial\" size=\"2\"><b>Omschrijving:</b> " 
    .$ticket['program'] ."</font></td>
    <td width=\"250\" valign=\"top\"><font face=\"arial\" size=\"2\"><b>Project:</b> " 
    .$ticket['project'] ."</font></td>
    <td width=\"150\" valign=\"top\"><font face=\"arial\" size=\"2\"><b>Internnr:</b> " 
    .$ticket['projectnum'] ."</font></td>
    </tr>
    </table>
    <table width=\"650\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"216\"><font face=\"arial\" size=\"2\">Akkoord door: $_SESSION[name]</font></td>
    <td width=\"216\"><font face=\"arial\" size=\"2\">Namens: " 
    .$ticket['bhnaam'] ."</font></td>
    <td width=\"216\"><font face=\"arial\" size=\"2\">Besteller: " 
    .$ticket['name'] ."</font></td>
    </tr>
    </table>
    <table width=\"650\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"3\">
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> <b>Aantal</b></font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> <b>Artikel</b></font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> <b>Artikelnummer</b></font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> <b>Excl. BTW</b></font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount1'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling1'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum1'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl1'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount2'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling2'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum2'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl2'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount3'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling3'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum3'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl3'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount4'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling4'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum4'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl4'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount5'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling5'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum5'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl5'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount6'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling6'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum6'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl6'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount7'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling7'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum7'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl7'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount8'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling8'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum8'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl8'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount9'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling9'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum9'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl9'] ."</font></td>
    </tr>
    <tr>
    <td width=\"75\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['amount10'] ."</font></td>
    <td width=\"350\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['bestelling10'] ."</font></td>
    <td width=\"125\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['artnum10'] ."</font></td>
    <td width=\"100\"><font face=\"arial\" size=\"2\"> " 
    .$ticket['excl10'] ."</font></td>
    </tr>
    </table>
    <br>
    <br>
    <table>
    <tr>
    <td><font face=\"arial\" size=\"2\">$_SESSION[name]</font></td>
    </tr>
    <tr>
    <td><img src=\"$_SESSION[handtekening]\" width=\"200\" height=\"67\"</td>
    </tr>
    </table>
    </body>
    </html>"



    $to "jhgd@domain.nl";

    $onderwerp "Bestelling 2009-" .$ticket['id'];

    $headers "MIME-Version: 1.0\r\n"
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"
    $headers .= "From:domain@domain.nl\r\n"
    $headers .= "CC:".$ticket[email].", ".$ticket[bhemail]."\r\n";

    mail($to$onderwerp$message$headers); 
      
      
    echo(
    "<SCRIPT> 
            alert('De inkoopbon is verzonden');
            
          </SCRIPT>"
    );
          
    }


    ?>


    <SCRIPT>

    function mailopdrachtFunctie()
    {
      var l=document.getElementById("mailopdrachtWaarde");
      l.value="JA";
      document.mailopdracht.submit();
    }

    function verzendForm1()
    {
      //alert("DOET UT"); 
      document.form1.submit();
    }


    </SCRIPT>
    I've looked into phpmailer, but it requires me to recode everything I have on the page, and thats not possible during time.

    Any ideas??

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    218
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question

    I've made some changes to the code, now the file is shown as it should (in the attachment), but the size is still incorrect and I still have an error message:

    Q298169.pdf can not be opened because the filetype is not supported or the file is damaged (because its send as an attachment or it is wrongly decoded).

    The code I use: (to attach an attachment)
    PHP Code:
    //add boundary string and mime type specification  
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";  
    //read the atachment file contents into a string, 
    //encode it with MIME base64, 
    //and split it into smaller chunks 
    list($tmp_id,$tmp_name) = explode('#',$ticket['attachments']);  
    /* Get attachment info */  
    $sql = "SELECT * FROM `".$hesk_settings['db_pfix']."attachments` WHERE `att_id`=$tmp_id LIMIT 1";  
    $result = hesk_dbQuery($sql);  
    if (hesk_dbNumRows($result) != 1)  
    {  
       hesk_error($hesklang['id_not_valid'].' (att_id)');  
    }  
    $file = hesk_dbFetchAssoc($result); 

    $attachment = chunk_split(base64_encode(file_get_contents($hesk_settings['server_path'].'/attachments/'.$file[saved_name])));  
    $ticket['attachments'] = $file['real_name'];  

    --PHP-mixed-<?php echo $random_hash?>   
    Content-Type: application/pdf; name="<?php echo $ticket['attachments']; ?>"   
    Content-Transfer-Encoding: base64   
    Content-Disposition: attachment   
      
    <?php echo $attachment?>  
    --PHP-mixed-<?php echo $random_hash?>--
    I can display the right size but this require me to remove the following 2 parts from the code:

    Content-Transfer-Encoding: base64

    chunk_split(base64_encode)

    Then only the error remains.

    I dont know why this error is keep coming up, please help.


  •  

    Posting Permissions

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