-1

I have a form HTML/PHP, simple, name, subject and comment, which is sent to my yahoo mail, and I have two problems, textarea for comments also sends HTML tags if some one put new line (enter) how to remove that and i got server/host name in subject when receive email, is there way to make some universal subject like name of my site or something like that instead of host name?

if(!isset($_POST['submit']))
{
$ToEmail = 'wired@yahoo.com';
$EmailSubject = 'Pitanje sa site.com';
$mailheader = "From :". $_POST["email"]. "\r\n";
$mailheader .= "Reply to :". $_POST["email"]. "\r\n";
$mailheader .= "Ova poruka sadrzi pitanje postavljeno na www.site.com \r\n";
$MESSAGE_BODY = "Ime : " .$_POST["name"]." \r\n";
$MESSAGE_BODY .= "Email : " .nl2br($_POST["email"])." \r\n";
$MESSAGE_BODY .= "Naslov : " .$_POST["subject"]." \r\n";
$MESSAGE_BODY .= "Poruka : " .nl2br($_POST["feedback"])." \r\n";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo "Vaša poruka je uspješno poslana! Kliknite <a href=\"index.html\">ovde</a> za početnu stranu ";
};
4

3 回答 3

3

好吧,我不是很明白你的问题,但它就在这里......

1) 你想删除 HTML 标签吗?如果是这样,请使用strip_tags()函数

2)你必须发送一个标题。例如,如果你使用mail()函数,你应该做这样的事情:

$to = 'destination@example.com';
$subject = 'Subject';
$message = 'Your Message';
$headers = 'From: Your Name <email@example.com>';
mail($to, $subject, $message, $headers);
于 2013-03-06T15:01:16.770 回答
0

您可以从您的表单中发送电子邮件,如下所示:

$to = "email@host.com";
$subject = "Your subject here";
$body = "The comment values here";
if (mail($to, $subject, $body)) {
    echo("<p>Message successfully sent!</p>");
} else {
    echo("<p>Message delivery failed...</p>");
}

要删除 html 新行,您可以使用该功能str_replace("<br/>","\n", $body);

或使用正则表达式的更好方法

$body = preg_replace("/<br */?>/","\n",$body); 
于 2013-03-06T15:02:29.473 回答
0

我认为您可以使用“nl2br”正确格式化文本区域。

另外,对于标头,您可以将它们格式化为您希望的格式,如果您使用带有 "From" 的标头,这应该删除服务器的名称:

$headers = 'From: Me <me@example.com>' . "\r\n";

然后

mail($to, $subject, $message, $headers);
于 2013-03-06T15:04:08.430 回答