Reputation: 1312
My code:
$to = '[email protected]';
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: [email protected]\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
mail($to, $subject, $message, $header);
When i send a mail with special characters such as ®ð-˚©-ʼ“æ,˚ˍðß©
,
in the message, it works but spacing is no longer dealt with (every new line or space gets removed)
And the second problem is that the special characters are not displayed in the subject.
They just output like: øʼªʼ
Thanks in advance!
Upvotes: 6
Views: 58650
Reputation: 1423
Content-Type: text/html
If you set this header that means you have to send HTML to the user. You can either decide to use something like TinyMCE to let the user write the message in a Word-style editor and use the HTML output from that. Or set your headers to plaintext.
Content-Type: text/plain
EDIT: Try this
$to = '[email protected]';
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: [email protected]\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
mail($to, $subject, $message, $header);
Upvotes: 12
Reputation: 31
I have used this header and this is worked for me...
$headers = '';
$headers = 'MIME-Version: 1.0'.PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1'.PHP_EOL;
$headers .= 'From: [email protected]<From: [email protected]>'.PHP_EOL;
Upvotes: 3
Reputation: 2332
Don't use mail() function. Use a fully crafted class that does (correctly) the job for you.
http://code.google.com/a/apache-extras.org/p/phpmailer/
Upvotes: 1
Reputation: 803
the problem with your code is because special characters need "special" charset too.
Try changing the charset=ISO to charset=UTF8...
Also, PHP mail() functions works ok, but you will find a lot more benefits and options if you go for a better solution like Swift Mailer
Upvotes: 0