PHP Mail header

≯℡__Kan透↙ 提交于 2019-11-28 05:13:17

问题


My code:

$to      = 'example@example.com';
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: noreply@example.com\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!


回答1:


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      = 'example@example.com';
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: noreply@example.com\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);



回答2:


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: webmaster@example.com<From: webmaster@example.com>'.PHP_EOL; 



回答3:


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/




回答4:


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



来源:https://stackoverflow.com/questions/15250140/php-mail-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!