我正在使用PHP從表單發送電子郵件。電子郵件和一切工作正常,但所給的數據已更改。例如,對於電子郵件正文輸入<textarea>
:POST數據更改
apostrophe: StackOverflow's members
new line:
end
給人的輸出電子郵件爲:
apostrophe: StackOverflow/'s members new line: end
所以它消除了新的生產線,並改變撇號'
到/'
這是我的代碼:
<h1>Send Email page</h1>
<?php if($_POST) {
$to = "[...omit...]";
$subject = "Message from ".$_POST["name"]."";
$header = "From: [email protected]\r\n";
$header .= "Reply-To: [...omit...]\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$msg = "Hello, <strong>".$_POST["name"]."</strong> has emailed.<br>";
$msg .= "Their phone number is:<strong> ".$_POST["phone"]."</strong><br>";
$msg .= "Their physical address is:<strong> ".$_POST["addr"]."</strong><br><br>";
$msg .= "Comments:<br><br>".$_POST["comment"]."";
mail($to, $subject, $msg, $header) or die ("Failure");
?>
<p>Thanks for your message.</p>
<?php } else { ?>
[...omit..]
<br><br>
<form action="index.php" method="post" name="contactForm">
<table id="emailform" style="width: 525px;">
<tr>
<td style="width: 40%;" class="bodytext">Your name:</td>
<td style="width: 60%;"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Phone Number:</td>
<td><input name="phone" type="text" id="phone" size="32"></td>
</tr>
<tr>
<td class="bodytext">Physical address:</td>
<td><input name="addr" type="text" id="addr" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comments:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext">enter email text here</textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php } ?>
似乎魔術引號在您的服務器啓用了有'\'' – tradyblix
那是什麼,以及我如何圍繞它得到什麼? – stackunderflow
嘗試'nl2br()'在你的textarea – Sammaye