0

所以,我的问题是我试图通过 PHP 发送邮件。我希望所有这些帖子都在一行中。但是使用 $header = "content-type: text/plain; charset=utf-8\r\n"; 这似乎是不可能的。当然,如果我删除那段代码,我就无法在邮件中显示 åäö。我已经在这里待了2天了。

<?php

$to = "info@mywebsite.se";
$subject = "Bokning från hemsidan.";
$header = "Content-type: text/plain; charset=utf-8\r\n";
$header .= "From: bokning@mywebsite.se\r\n";
$body = "En bokning:" . "\n\n" .
    $_POST["namn"] . "\n" .
    $_POST["mobilnummer"] . "\n" .
    $_POST["hemnummer"] . "\n" .
    $_POST["email"] . "\n" .
    $_POST["gatuadress"] . "\n" .
    $_POST["postnummer"] . "\n" .
    $_POST["vaning"] . "\n" .
    $_POST["portkod"] . "\n" .
    $_POST["bokningsdag"] . "\n" .
    $_POST["byggstadning"] . "\n" .
    $_POST["flytthjalp"] . "\n" .
    $_POST["flyttstadning"] . "\n" .
    $_POST["typavbostad"] . "\n" .
    $_POST["fonsterputsning"] . "\n" .
    $_POST["kontorsstadning"] . "\n" .
    $_POST["rojningbortforsling"] . "\n" .
    $_POST["visningsstad"] . "\n" .
    $_POST["dodsbo"] . "\n" .
    $_POST["boyta"] . "\n" .
    $_POST["kallare"] . "\n" .
    $_POST["vind"] . "\n" .
    $_POST["totalkvm"] . "\n" .
    $_POST["garage"] . "\n" .
    $_POST["forrad"] . "\n" .
    $_POST["veranda"] . "\n" .
    $_POST["balkongglas"] . "\n" .
    $_POST["balkongejglas"] . "\n" .
    $_POST["friggebod"] . "\n" .
    $_POST["fakgatuadress"] . "\n" .
    $_POST["fakpostnummer"] . "\n" .
    $_POST["jarut"] . "\n" .
    $_POST["nejrut"] . "\n" .
    $_POST["meddelande"];


if($_POST){
    mail($to, $subject, $body, $header);
    $feedback = "Tack för din bokning! Vi kommer att kontakta dig inom kort via mail eller telefon för att bekräfta din bokning. Vid bråskande ärenden var vänlig ring kontoret. Våra telefontider är 8.00-12.30.";
}
?>
4

3 回答 3

1

\r\n works for e-mail newlines, as required by RFC2822:

Messages are divided into lines of characters. A line is a series of characters that is delimited with the two characters carriage-return and line-feed; that is, the carriage return (CR) character (ASCII value 13) followed immediately by the line feed (LF) character (ASCII value 10). (The carriage-return/line-feed pair is usually written in this document as "CRLF".)

See also: Comment on php.net regarding "low quality Unix MTAs" requiring \n instead of \r\n

\r is CR, \n is LF in PHP

I probably should have stated that this is only valid for Content-Type:text/plain, but mail systems are supposed to be created to fit all relevant RFCs from the Internet Engineering Task Force including the above-mentioned section. If you are sending HTML instead, use <BR /> instead.

于 2013-10-22T22:45:37.197 回答
0

According to php.net, you must separate each line with "\r\n".

于 2013-10-22T22:47:08.037 回答
0

正如其他人所提到的, \r\n 是电子邮件标题的换行符。如果您查看“换行符”上的 Wikipedia 页面,您会看到该角色的几种表示形式。

基于 ASCII 或兼容字符集的系统单独使用 LF(换行符,'\n',0x0A,十进制的 10)或 CR(回车,'\r',0x0D,十进制的 13),或 CR 后跟LF (CR+LF, '\r\n', 0x0D0A)

Unicode 标准定义了大量符合应用程序应识别为行终止符的字符:[4]
LF:换行符,U+000A
...
CR:回车符,U+000D

您可以尝试在 UTF-8 正文中传递“\0\r\0\n”,看看是否得到了您希望的换行符。

于 2013-10-24T19:52:06.737 回答