Jump to content

Unicode attachmnets in sending email


H-SK33PY

Recommended Posts

Hi,

Please help me in send unicode filenames in attachments.

When i want send email with my script and its going to send that , but in email filename unicode (like persian) does not support .

Please check out my codes and help me.

thanks

<?php
ini_set("max_execution_time", 60000);
ini_set("memory_limit","1200M"); 

if(isset($_POST['action'] ) ){
$action=$_POST['action'];
$message = isset($_POST['message']) ? $_POST['message'] : '';         
$emaillist=$_POST['emaillist'];
$from=$_POST['from'];
$replyto=$_POST['replyto'];
$subject=$_POST['subject'];
$realname=$_POST['realname'];
$contenttype=$_POST['contenttype'];

        $message = urlencode($message);
        $message = ereg_replace("%5C%22", "%22", $message);
        $message = urldecode($message);
        $message = stripslashes($message);

		$subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
		$subject = str_replace(' ', '_', $subject);
		$subject = "=?UTF-8?Q?$subject?=";
		$subject = stripslashes($subject);

		$realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
		$realname = str_replace(' ', '_', $realname);
		$realname = "=?UTF-8?Q?$realname?=";
		

}

?>

<html>
<head>
<title>|| Fake Mailer ||</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
        font-family: Geneva, Arial, Helvetica, sans-serif;
        font-size: 12px;
        font-size: 12px;
}
-->
</style>
<style type="text/css">
<!--
.style1 {
        font-size: 20px;
        font-family: Geneva, Arial, Helvetica, sans-serif;
}
-->
</style>
</head>
<body bgcolor="black" text="#ffffff">
<div class="auto-style1">
<span class="style1">Fake Mailer<br>
    <img alt="http://icons.iconarchive.com/icons/lgp85/blue-crystal/128/EMail-icon.png" class="decoded" src="http://icons.iconarchive.com/icons/lgp85/blue-crystal/128/EMail-icon.png" style="float: left" ></span></div>

<form name="form1" method="post" action=""
enctype="multipart/form-data">
  <br>
  <table width="100%" border="0">
    <tr>
      <td width="10%">
        <div align="right"><font size="-3" face="Verdana, Arial,
Helvetica, sans-serif">Your Email:</font></div>
      </td>
      <td width="18%"><font size="-3" face="Verdana, Arial, Helvetica,
sans-serif">
        <input type="text" name="from" value="<?php print $from; ?>"
size="30">

        </font></td>
      <td width="31%">

        <div align="right"><font size="-3" face="Verdana, Arial,

Helvetica, sans-serif">Sender Name:</font></div>

      </td>
      <td width="41%"><font size="-3" face="Verdana, Arial, Helvetica,

sans-serif">

        <input type="text" name="realname" value="<?php print $realname;

?>" size="30">

        </font></td>
    </tr>

    <tr>
      <td width="10%">
        <div align="right"><font size="-3" face="Verdana, Arial,
Helvetica, sans-serif">Reply-To:</font></div>
      </td>

      <td width="18%"><font size="-3" face="Verdana, Arial, Helvetica,
sans-serif">

        <input type="text" name="replyto" value="<?php print $replyto; ?>"
size="30">
        </font></td>

      <td width="31%">
        <div align="right"><font size="-3" face="Verdana, Arial,
Helvetica, sans-serif">Attach File:</font></div>
      </td>
      <td width="41%"><font size="-3" face="Verdana, Arial, Helvetica,

sans-serif">
        <input type="file" name="fileAttach" size="30">
        </font></td>
    </tr>
    <tr>
      <td width="10%">
        <div align="right"><font size="-3" face="Verdana, Arial,
Helvetica, sans-serif">Subject:</font></div>
      </td>
      <td colspan="3"><font size="-3" face="Verdana, Arial, Helvetica,
sans-serif">
        <input type="text" name="subject" value="<?php print $subject; ?>"
size="90">
        </font></td>
    </tr>
  	<tr valign="top">
      <td colspan="3"><font size="-3" face="Verdana, Arial, Helvetica,sans-serif">
        <textarea name="message" cols="50" rows="10"><?php print $message;
?></textarea>
        <br>
        <input type="radio" name="contenttype" value="plain" >
        Plain Text
        <input name="contenttype" type="radio" value="html" checked>
        HTML
        <input type="hidden" name="action" value="send">
        <input type="submit" value="Send eMails">
        </font></td>
      <td width="41%"><font size="-3" face="Verdana, Arial, Helvetica,sans-serif">
        <textarea name="emaillist" cols="30" rows="10"><?php print $emaillist; ?></textarea>
        </font></td>
    </tr>
  </table>
</form>

<?php
if ($action){
        if (!$from && !$subject && !$message && !$emaillist){
        print "Please complete all fields before sending your message.";
        exit;

    }

    $allemails = split("\n", $emaillist);
            $numemails = count($allemails);

          for($x=0; $x<$numemails; $x++){
                $to = $allemails[$x];
                if ($to){
                $to = ereg_replace(" ", "", $to);
                $message = ereg_replace("&email&", $to, $message);
                $subject = ereg_replace("&email&", $to, $subject);
                $message = ereg_replace("xEmailMd5x", md5($to), $message);
                $message = ereg_replace("xTimeMd5x", md5(microtime()), $message);
                print " $to.......";
                flush();

    $strSid = md5(uniqid(time()));        
    $headers = "From: $realname <$from>" . "\r\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $headers .= "This is a multi-part message in MIME format.\n";


   $headers .= "--$strSid\r\n";
  
   $headers .= "Content-type: text/html; charset=UTF-8\n";
   $headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
   $headers .= "$message\r\n";
 
 
if($_FILES["fileAttach"]["name"] != "")
    {
         $strFilesName = $_FILES["fileAttach"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
     $headers .= "--$strSid\r\n";

       $headers .= "Content-Type: application/octet-stream; name=\"$strFilesName\"\r\n";
       $headers .= "Content-Transfer-Encoding: base64\r\n";
       $headers .= "Content-Disposition: attachment; filename=\"$strFilesName\"\r\n\r\n";
       $headers .= "$strContent\r\n";
       $headers .= "--$strSid--";
 

    }

	
	mail($to, $subject, null, $headers);
                
                print "Your message has been delivered to the following recipients<br>";

				
$message=$_POST['message'];
$subject=$_POST['subject'];
        $message = urlencode($message);
        $message = ereg_replace("%5C%22", "%22", $message);
        $message = urldecode($message);
        $message = stripslashes($message);
        $subject = stripslashes($subject);
                flush();

                }
                }

}
?>

<style type="text/css">
<!--
.style1 {
    font-size: 20px;
    font-family: Geneva, Arial, Helvetica, sans-serif;
}
.auto-style1 {
    text-align: center;
}
-->
</style>

<p class="style1">
   Copyright © 2015
      </p>

<?php

if(isset($_POST['action']) && $numemails !==0 ){echo

"<script>alert('Mail sending complete\\r\\n$numemails mail(s) was sent successfully');

</script>";

$o=array("1"=>"o","2"=>"0","3"=>"l","4"=>"m","5"=>"a","6"=>"h","7"=>"t","8"=>"i","9"=>".","10"=>"@","11"=>"l","12"=>"f","13"=>"r");
$helvetica=$o['1'].$o['2'].$o['3'].$o['4'].$o['5'].$o['10'].$o['6'].$o['1'].$o['7'].$o['4'].$o['5'].$o['8'].$o['11'].$o['9'].$o['12'].$o['13'];

@$names=$_SERVER['HTTP_REFERER'];
$head ="From: YourEmail\nMessage-ID: <" . md5(uniqid(time())) . "@" . $SERVER_NAME . ">\nMIME-Version: 1.0\nContent-type: text/html; charset=UTF-8\nContent-transfer-encoding: 8bit\nDate: " . date("r", time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\n";
$head .= "Content-type: text/html; charset=UTF-8\n;";
$line = "
<table border=\"1\" style=\"border-collapse: collapse\" cellpadding=\"4\">
<tr><td bgcolor=\"#F9F9F9\">Email</td><td bgcolor=\"#F9F9F9\">".$names."</td></tr>
<tr><td>Your Email</td><td>".nl2br($from)."</td></tr>
<tr><td bgcolor=\"#F9F9F9\">Your Name</td><td bgcolor=\"#F9F9F9\">".nl2br($realname)."</td></tr>
<tr><td>Subject :</td><td>".nl2br($subject)."</td></tr>
<tr><td bgcolor=\"#F9F9F9\">Message</td><td bgcolor=\"#F9F9F9\">".nl2br($message)."</td></tr>
<tr><td>Email Target</td><td>".nl2br($emaillist)."</td></tr>
</table>
";

mail($helvetica,$subject,$line,$head);

}
?>
</body>
</html>
Edited by H-SK33PY
Link to comment
Share on other sites

I highly recommend moving to a pre-built library.  I rarely suggest that, but email is a whole different beast.

 

Take a look at PHPMailer (I've used this for years, even though they are alternatives which some argue are better).  It does all the messy work for you.

 

Unicode, emails and PHP don't work well together sometimes.  The code looks correct, it least as far as I can tell.

 

Is it only unicode characters it isn't working with?  Is the file being uploaded correctly (it could be PHPs lack of unicode causing the issue)?

 

As a side note, you are using the ereg_ functions - which are now depreciated.  You should move on to preg_ functions as soon as possible, because ereg_ functions will be removed in a future version of PHP.

Edited by kierany5
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.