Jump to content

Upload Attachments & Contents/HTML Images


Joob
 Share

Recommended Posts

Hello mates,
 
I'm having difficulty uploading the attachments to download the attached image or file .. the link is always incorrect.
 
And in the message field, I am not able to make the messages appear in HTML format, for example, if you want to put an image in the message, it does not appear anything ..
 
I have the following code
$letter_html = "";
// $op_getKey = preg_match_all("/alternative; boundary=\"(.*)\"/", $email_body, $getKey);
$op_getKey = preg_match_all("/boundary=\"(.*)\"/", $email_body, $getKey);
$has_attachment = preg_match_all("/multipart\/mixed/", $email_body, $attachment);
if ($op_getKey) {
    if ($has_attachment) {
        $mailParts = explode("--" . $getKey[1][1], $email_body);
        $attachParts = explode("--" . $getKey[1][0], $email_body);
    
        $get_attach_name=preg_match_all("/filename=\"(.*?)\"/", $attachParts[2], $attach_name);
        $get_attach_type=preg_match_all("/Content-Type: (.*?);/", $attachParts[2], $attach_type);
        $pure_code = explode("\n\n",$attachParts[2]);
        $pure_code = str_replace("\r","",$pure_code[1]);
        $pure_code = str_replace("\n","",$pure_code);
    }else{
        $mailParts = explode("--" . $getKey[1][0], $email_body);
    }
    // $letter_text = str_replace('Content-Type: text/plain; charset="UTF-8"', '', $mailParts[1]);
    // echo $letter_text;

    $the_mail = $mailParts[2];


    $to_replace = array(
        'Content-Type: text/html; charset="UTF-8"',
        'Content-Type: text/html; charset=UTF-8',
        'Content-Type: text/html; charset="utf-8"',
        'Content-Type: text/html; charset=utf-8',
        'Content-Type: text/html; charset="iso-8859-1"',
        'Content-Type: text/html; charset=iso-8859-1',
        'Content-Type: text/html; charset="ISO-8859-1"',
        'Content-Type: text/html; charset=ISO-8859-1',
        'Content-Type: text/plain; charset="iso-8859-1"',
    );

    foreach ($to_replace as $k => $v) {
        $the_mail = str_replace($to_replace[$k], '', $the_mail);
    }
    
     //$the_mail = str_replace('Content-Type: text/html; charset="UTF-8"', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset=UTF-8', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset="utf-8"', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset=utf-8', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset="iso-8859-1"', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset=iso-8859-1', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset="ISO-8859-1"', '', $the_mail);
     //$the_mail = str_replace('Content-Type: text/html; charset=ISO-8859-1', '', $the_mail);


    if (preg_match_all("/Content-Transfer-Encoding: quoted-printable/", $the_mail, $mailToDecode)) {
        $message_to_decode = str_replace('Content-Transfer-Encoding: quoted-printable', '', $the_mail);
        $letter_html = quoted_printable_decode($message_to_decode);
    }elseif(preg_match_all("/Content-Transfer-Encoding: base64/", $the_mail, $mailToDecode)){
        $message_to_decode = str_replace('\r', '', $the_mail);
        $message_to_decode = str_replace('\n', '', $message_to_decode);
        $message_to_decode = str_replace('Content-Transfer-Encoding: base64', '', $message_to_decode);
        $letter_html = base64_decode($message_to_decode);
        // $letter_html = $message_to_decode;
    } else {
        $letter_html = $the_mail;
    }
    // echo $letter_html;
} else {


    $mailParts = explode("\n\n", $email_body);



    foreach ($mailParts as $k => $v) {
        if ($k > 0) {
            $letter_html .= $v . "\n\n";
        }
    }

    if(preg_match_all("/Content-Transfer-Encoding: base64/", $email_body, $mailToDecode)){
        $message_to_decode = str_replace('\r', '', $letter_html);
        $message_to_decode = str_replace('\n', '', $message_to_decode);
        $letter_html = base64_decode($message_to_decode);
        
        // $letter_html = $message_to_decode;
    }

I use the following for the Annexes

<a target="_blank" href="data:<?=$attach_type[1][0]?>;base64,<?=$pure_code?>"><?=$attach_name[1][0]?></a>

And I use the following for message information

<?=$letter_html?>
Let me see if you can help me;)
 
 
Thank you,
Best Regards

 

Link to comment
Share on other sites

Oh yes, of course sorry..

I can send the image in attachments, but when I want to download, the link is always wrong .. and when I put the image in the field, doesn't show nothing.

Check the example with the image.. (Attach)
 

 

 

post-174279-0-99923400-1504118866_thumb.png

Edited by Joob
Link to comment
Share on other sites

Still don't have a clue what you are doing.

 

To me:

A download is your script moving a file to your client.

 

An attachment is something you append to an EMAIL

 

So what do you mean when you use those terms?

 

Do you have php error checking turned on for this problem?  (my signature)

Link to comment
Share on other sites

Yes, I use my script to service for email online..

 

And so when I send an email to my service online I receive the email but when I send with the text include image .. I cant receive the email with the image.. I can show an example..

 

And when I send an attachment the link of the image or file doesn't work .. u can check in Attached..

Link to comment
Share on other sites

I have an email service .. and when sending an attachment to my site of my email, the link in the attachment is not functional, give me a link that does not exist .. that is, I wanted it when I sent an image, which opened in the browser and when it was a file, you can download it.

 

 

The other problem is, when sending or receiving picture emails, in the text field, I get the entire email encoded, as it is in the attachment above.

 

 

I do not know if you can understand my question.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.