Forum Moderators: coopster

Message Too Old, No Replies

PHP mail with utf-8 charset

PHP mail with utf-8 charset

         

nextnet

7:17 am on Aug 13, 2011 (gmt 0)

10+ Year Member



Hello once again webmasterworld,

The issue I am having is probably easy to handle by an
average PHP programmer.. My PHP knowledge is limited
though and I would appreciate any help..

I have a PHP class that sends plain e-mails.. This is
part of another script.. What I am trying to achieve is to make the class send e-mails in utf-8 encoding..

There are a lot of examples on how to do this on the web
but I couldn't implement it with my script no matter how
I tried..

So here's the code and if anyone can help it would be
great..



class Mailer
{
var $mConfig;

/**
* Initialize class constructor
*/
function Mailer()
{
}

/**
* Send email to recepient
*/

function sendEmail($aEmail, $aSubject, $aBody, $aFrom, $aReplyto)
{
return mail($aEmail, $aSubject, $aBody, "From: {$aFrom}\r\n"."Reply-To: {$aReplyto}\r\n");
}

/**
* Sends email when editor action happens
*/

function sendAffMail($aAction, $aEditor)
{
$subject = $this->mConfig["{$aAction}_subject"];
$body = $this->mConfig["{$aAction}_body"];

$subject = str_replace('{own_site}', $this->mConfig['site'], $subject);

$body = str_replace('{editor_username}', $aEditor['username'], $body);
$body = str_replace('{editor_pwd}', $aEditor['password2'], $body);
$body = str_replace('{own_site}', $this->mConfig['site'], $body);
$body = str_replace('{own_url}', $this->mConfig['base'], $body);
$body = str_replace('{own_email}', $this->mConfig['site_email'], $body);

$body = stripslashes($body);

return $this->sendEmail($aEditor['email'], $subject, $body, $this->mConfig['site_email'], $this->mConfig['site_email']);
}
}
?>

coopster

4:08 pm on Aug 31, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You would have to modify your function to send an additional header (Content-Type). See the PHP mail() function page for more information, particularly the examples. You can also find an example in the user contributed notes (search the page for utf-8).

[php.net...]