Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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联系人表单编码问题_Php_Html_Forms_Email_Post - Fatal编程技术网

Php联系人表单编码问题

Php联系人表单编码问题,php,html,forms,email,post,Php,Html,Forms,Email,Post,我为我的网站创建的联系人表单有问题。我不是PHP专家,但我认为一个合适的联系方式比一个简单的href mailto链接更专业。 我设法得到了电子邮件,它告诉我发件人,但没有主题,没有文本,只是一片空白。此外,我每天都会收到2封没有发件人的电子邮件 这就是我在PHP中名为contact.PHP的页面中所做的。 我希望你能帮助: <?php $name = $_POST['name']; $email = $_POST['email']; $form1_services = $_POST['

我为我的网站创建的联系人表单有问题。我不是PHP专家,但我认为一个合适的联系方式比一个简单的href mailto链接更专业。 我设法得到了电子邮件,它告诉我发件人,但没有主题,没有文本,只是一片空白。此外,我每天都会收到2封没有发件人的电子邮件

这就是我在PHP中名为contact.PHP的页面中所做的。 我希望你能帮助:

<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$form1_services = $_POST['form1_services'];
$msg = $_POST['msg'];
$formcontent="From: $name \n Message: $message";
$recipient = "dandrea.alessandro81@gmail.com";
$subject = "Customer Inquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Keep in touch soon!" . " -" . "<a href='index.html'           style='text-decoration:none;font-family: 'gooddogregular';color:#009999;'>     Return Home</a>";

这是HTML中的实际形式:

<form action="contact.php" method="post">
    <fieldset>
        <legend></legend>
        <div class="controlgroup">
            <label for="form1_name">Name *</label>
                <input type="text" placeholder="Enter your full name*" name="name" value>
        </div>
        <div class="controlgroup">
            <label for="form1_email">Email *</label>
                <input type="text" placeholder="Enter a valid email address*" name="email" value>
        </div>
        <div class="controlgroup">
            <label for="form1_services">Services Required</label>
                <select id="form1_services" name="services">
                    <option value="Website Design"> Website Design (from scratch) </option>
                    <option value="Resposive Design"> Responsive Design </option>
                    <option value="Customize a Site"> Customize a Site </option>
                    <option value="Quotation"> Quotation </option>
                </select>
        </div>
        <div class="controlgroup">
            <label>Project Info*</label>
                <textarea placeholder="Ciao Alessandro, I am contacting you because...*" id="msg" name="msg" required aria-required="true"></textarea>
        </div>
            <input type="submit" name="submit_btn" id="send" value="Hit me up!" class="wow rubberBand animated" data-wow-delay="2s">
    </fieldset>         
</form>

名字*
电子邮件*
所需服务
网站设计(从头开始)
响应性设计
自定义站点
引用
项目信息*
先谢谢你。
Alessandro

尝试添加一些标题:

    $mailheader = "From: $email \r\n";
    $mailheader .= "MIME-Version: 1.0\r\n";
    $mailheader .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

看看您的PHP,您正在收集大量字段,但实际上并没有使用它们。试试这个:

<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$form1_services = $_POST['services'];
$msg = $_POST['msg'];

$message = 'From: ' . $name . ' <' . $email . '>' . "\n";
$message .= 'Service: ' . $form1_services . "\n";
$message .= 'Message: ' . "\n";
$message .= $msg;

$recipient = "dandrea.alessandro81@gmail.com";
$subject = "Customer Inquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $message, $mailheader) or die("Error!");
echo "Thank You! Keep in touch soon!" . " -" . "<a href='index.html'           style='text-decoration:none;font-family: 'gooddogregular';color:#009999;'>     Return Home</a>";

Add
echo(“”.$\u POST['name']”

编码到您的php中,以确保您确实从表单中获取数据。作为一个警示,正如@samlev所提到的,您需要实施验证,这样就不会有人劫持您的表单发送垃圾邮件。还要注意您使用的索引来自
name
html属性。您要求的是
$\u POST['form1\u services']
,但实际上它是作为
服务发送的。嗨,samlev,非常感谢您的帮助。我刚试过你的代码,终于开始工作了。唯一的问题是,电子邮件会转到我的垃圾邮件中。你认为可以修复吗?最好的选择是不要让它来自用户(这很容易被滥用,大多数邮件客户端会发现发件人与实际发送它的服务器不匹配)。你的姓名和电子邮件都在正文中,所以只需从你自己的电子邮件地址发送,或者你可以设置一个gmail过滤器来捕获所有的联系请求。我还要注意,将未初始化的
from
作为标题是个坏消息。我可以将我的电子邮件地址设置为
test@example.com\r\nBCC:spamtarget@example.com, spamtarget2@example.com, morespam@example.com
然后它会在你不知情的情况下给其他多人发送电子邮件。嗨@Alessandro,如果答案真的对你有帮助,请勾选正确答案。