Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mail()以.txt文件的形式发送消息_Php - Fatal编程技术网

Php mail()以.txt文件的形式发送消息

Php mail()以.txt文件的形式发送消息,php,Php,我对PHP非常陌生,所以不要介意@。。。这是一个快速修复打开脚本没有错误 我目前正在编写一个邮件脚本,它运行得非常好。 遗憾的是,它将用户输入的文本发送为.txt文件,而不是纯文本 基本上,表单存储在messenger\u mailsend.php中,文本区域的内容通过使用$\u POST[]进入messenger\u mailsend\u controller.php @$inhalt = $_POST['inhalt']; $message = strip_tags($inh

我对PHP非常陌生,所以不要介意
@
。。。这是一个快速修复打开脚本没有错误

我目前正在编写一个邮件脚本,它运行得非常好。 遗憾的是,它将用户输入的文本发送为
.txt
文件,而不是纯文本

基本上,表单存储在
messenger\u mailsend.php
中,文本区域的内容通过使用
$\u POST[]
进入
messenger\u mailsend\u controller.php

    @$inhalt = $_POST['inhalt'];
    $message = strip_tags($inhalt);

    if(isset($_POST['submit'])){
    @mail($mailto, $subject, 'why not zoidberg?', $headers); 
    echo 'The mail was sent!';
    }
“为什么不zoidberg”是我用来检查var是否有问题的测试文本,实际上它说的是
mail($mailto,$subject,$message,$headers)

是用于从表单中获取键入的消息、删除标记并将其存储为
$message
的代码

如果我做一个
var_dump
它会说“我是内容”(表单中键入的内容)。。 当
$message
var被一些纯文本替换时,它仍然以
text.txt

我用于$headers的代码是:

    $headers .= 'From:' . $usrmail . "\n";
$headers .= 'Reply-To:' . $reply . "\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\n";
$headers .= 'X-Sender-IP:' . $_SERVER['REMOTE_ADDR'] . "\n";
$headers .= 'Content-type: text/html; charset=ISO-8859-1\r\n';

$headers .= 'Cc: ' . $cc . "\n";
$headers .= 'Bcc: ' . $bcc . "\n";

--解决方案:通过将内容类型设置为文本/纯文本,它可以工作,谢谢大家--

那么,当您在发送之前剥离所有html标记时,您如何期望邮件以html格式发送

但是,如果要发送html邮件,则必须在发送前在标题中定义相同的内容。请参见代码片段:

$to = 'bob@example.com';
$subject = 'Website Change Reqest';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

@$inhalt = $_POST['inhalt'];
$message = strip_tags($inhalt);
然后你就这样发送邮件:

mail($to, $subject, $message, $headers);

请发布邮件功能的调用为什么要正确检查是否设置了
$\u post['inhalt']
?使用
@
既糟糕又懒惰。您在$mailto、$subject和$headers中放了什么?用$message替换“为什么不zoidberg”。并发布完整的代码……如果我不删除标记,则没有区别:/n如果不删除它们,文件的内容是“Im content

”,只需删除其“Im content”即可,然后在执行邮件()之前,您必须附加上面代码段中提到的$header变量……您需要在发送邮件之前定义内容类型。请记住,默认为jst纯txt格式。