/    Sign up×
Community /Pin to ProfileBookmark

E-mail with Mail function does not show special characters? Why

I have mail function and it does not show characters in e-mail as in db on server. I have set charset=utf-8. Do you know why?

[code=php]

$html = true;

send_mime_mail($recipient, $subject, $message, $headers, $html, $attachments);

function send_mime_mail($recipient, $subject, $message, $headers = NULL, $html = NULL, $attachments = NULL, $css = NULL)
{

if (!function_exists(‘mime_content_type’)){
function mime_content_type($file){
if(!is_readable($file)) return false;
@$size = getimagesize($file);
if(!empty($size[‘mime’])){
return($size[‘mime’]);
}else{
$extensions = array(‘doc’ => ‘application/msword’, ‘html’=> ‘text/html’, ‘htm’ => ‘text/html’,
‘pdf’ => ‘application/pdf’, ‘ppt’ => ‘application/vnd.ms-powerpoint’, ‘rtf’ => ‘text/rtf’,
‘xls’ => ‘application/vnd.ms-excel’, ‘zip’ => ‘application/zip’);
$keys = array_keys($extensions);
$parts = array_reverse(explode(‘.’, $file));
$extension = $parts[‘0’];
if(in_array($extension, $keys)) return $extensions[$extension];
$data = file_get_contents($filename);
$bad = false;
for($x = 0, $y = strlen($data); !$bad && $x < $y; $x++)
{
$bad = (ord($data{$x}) > 127);
}
if(!$bad) return (‘text/plain’);
return(‘application/octet-stream’);
}
}
}
function convert_links($string, $protocol = TRUE)
{
$search[] = ‘/<as[^>]*href=[‘”]mailto:([^'”]+)[‘”][^>]*>([^<]+)</a>/i’;
$search[] = ‘/<as[^>]*href=mailto:([^s>]+)[^>]*>([^<]+)</a>/i’;
$search[] = ‘/<as[^>]*href=[‘”](http://[^'”]+)[‘”][^>]*>([^<]+)</a>/i’;
$search[] = ‘/<as[^>]*href=(http://[^s>]+)[^>]*>([^<]+)</a>/i’;
$replace = ‘2 (1)’;
return(strip_tags(preg_replace($search, $replace, $string)));
}

function html_to_plain($string)
{
$string = preg_replace(“(rn|n|r)”, ‘ ‘, $string);
$string = preg_replace(‘/<p>/i’, “nn”, $string);
$string = preg_replace(‘/(<br>|<br />)/i’, “n”, $string);
return (convert_links($string));
}
if(!isset($css)) $css = ”;
// Generate a boundary string
$mime_boundary = “mime_boundry_multipart/mixed”.md5(time()).”x”;
$alternative_mime_boundary = “mime_boundry_multipart/alternative_”.md5(time()).”x”;

if(empty($headers)) $headers = ”;
$headers .= “nMIME-Version: 1.0n”;

if(count($attachments) > 0){
$headers .= “Content-Type: multipart/mixed;n” .
” boundary=”{$mime_boundary}”nn”;

if(!empty($html) and $html == TRUE){
$content = “This is a multi-part message in MIME format.nn”.
“–{$mime_boundary}n”.
“Content-Type: multipart/alternative;n”.
” boundary=”{$alternative_mime_boundary}”nn”.
“–{$alternative_mime_boundary}n”.
“Content-Type: text/plain; charset=utf-8; format=flowedn”.
“Content-Transfer-Encoding: 7bitnn”.
html_to_plain($message).”nn”.
“–{$alternative_mime_boundary}n”.
“Content-Type: text/html; charset=utf-8n”.
“Content-Transfer-Encoding: 7bitnn”.
“<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>n”.
“<html>n”.
“<head>n”.
” <style type=”text/javascript”>n”.
” $css n”.
” </style>n”.
” <meta content=”text/html;charset=utf-8″ http-equiv=”Content-Type”>n”.
” <title></title>n”.
“</head>n”.
“<body>n”.
$message.”n”.
“</body>n”.
“</html>nn”.
“–{$alternative_mime_boundary}–n”;
}else{
$content = “This is a multi-part message in MIME format.nn”.
“–{$mime_boundary}n”.
“Content-Type: text/plain; charset=utf-8; format=flowedn” .
“Content-Transfer-Encoding: 7bitnn” .
convert_links($message).”nn”;
}

// Deal with attachments array
if(count($attachments) > 0){
foreach($attachments as $key => $value){
$mime_type = mime_content_type($value);
if(is_file($value) and is_readable($value) ){
if(ereg(‘^image’, $mime_type)){
$disposition = ‘inline’;
}else{
$disposition = ‘attachment’;
}
$filesize = filesize($value);
$file = fopen($value,’rb’);
$data = fread($file,$filesize);
fclose($file);

// Base64 encode the file data
$data = chunk_split(base64_encode($data));
$value = pathinfo($value);
$content .= “–{$mime_boundary}n” .
“Content-Type: $mime_type;n” .
” name=”{$value[‘basename’]}”n” .
“Content-Transfer-Encoding: base64n” .
“Content-Disposition: $disposition;n” .
” filename=”{$value[‘basename’]}”nn” .
$data . “n”;
}
}
}

$content .= “–{$mime_boundary}–n”;

}elseif(!empty($html) and $html == TRUE){
$headers .= “Content-Type: multipart/alternative;n”.
” boundary=”{$alternative_mime_boundary}”nn”;
$content = “–{$alternative_mime_boundary}n”.
“Content-Type: text/plain; charset=utf-8; format=flowedn”.
“Content-Transfer-Encoding: 7bitnn”.
html_to_plain($message).”nn”.
“–{$alternative_mime_boundary}n”.
“Content-Type: text/html; charset=utf-8n”.
“Content-Transfer-Encoding: 7bitnn”.
“<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>n”.
“<html>n”.
“<head>n”.
” <style type=”text/javascript”>n”.
” $css n”.
” </style>n”.
” <meta content=”text/html;charset=utf-8″ http-equiv=”Content-Type”>n”.
” <title></title>n”.
“</head>n”.
“<body>n”.
$message.”n”.
“</body>n”.
“</html>nn”.
“–{$alternative_mime_boundary}–n”;

}else{
$headers .= “Content-Type: text/plain; charset=utf-8; format=flowedn” .
“Content-Transfer-Encoding: 7bitnn”;
$content = convert_links($message).”n”;
}
if(mail($recipient, $subject, $content, $headers)) return TRUE;
return FALSE;
}
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYOct 18.2005 — you appear to be calling the function send_mime_mail() before defining it
Copy linkTweet thisAlerts:
@toplisekauthorOct 18.2005 — It works also this. Problem are characters. Do you have suggestions?
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...