Jump to content

Send UTF-8 e-mail message using PHP


filoaman

Recommended Posts

Hello friends.

First of all note that i'm just an amateur php programmer, so please if what i ask is very dam don't shoot me...

I already search the form and found some solutions to send  UTF-8 e-mail message using PHP, but for some reason i have to use the above code.

The problem is that this code doesn't send  UTF-8 e-mail messages.

If you can help me please do it.

Thank you

 

<? php
$subject = "my subject in UTF-8";
$emailadd = 'mail@mail.com';
$url = "http://www.mySite.com/";
$req = '0'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.


$text = "Results from form:\n\n";       
$space = '  ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
	if ($value == '')
	{echo "$key is empty";die;}
}
$j = strlen($key);
	if ($j >= 40)
	{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 40 - $j;
	for ($i = 1; $i <= $j; $i++)
	{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = '  ';
}

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh charset=utf-8 CONTENT="0; URL='.$url.'">';

?>

 

Link to comment
Share on other sites

@jorgepinho

Thank you for your answer.

 

I had already visit, read and try examples from the web page you suggest.

My problem is that i can't understand where to put this "magic line"

$headers = 'Content-type: text/html; charset=utf-8' . "\r\n";

...and how to use this variable ("$headers").

I try something like this:

mail($emailadd, $subject, $text, 'From: '.$emailadd., $headers'');

but in this case the mail function don't even send the mail!

 

Can you help me more please with the "4th argument", what do you mean exactly?

 

Thanks

Link to comment
Share on other sites

Hi,

 

You need to learn PHP syntax also, here is an example I *copied* from that page:

 

Change it to your needs

 

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';

$headers = 'From: webmaster@example.com' . PHP_EOL.
$headers .= 'Reply-To: webmaster@example.com' . PHP_EOL .
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;

mail($to, $subject, $message, $headers);

 

 

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.