Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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提交HTML表单_Php_Html_Forms_Post - Fatal编程技术网

通过PHP提交HTML表单

通过PHP提交HTML表单,php,html,forms,post,Php,Html,Forms,Post,尝试通过PHP将HTML5表单提交到电子邮件,并在成功提交后重定向到“谢谢!”页面。问题是,表单没有发送,重定向也没有发生 这是我的HTML: <form id="vendorInfo" action="process_form_vendor.php" method="post"> <label for="vendorName">Vendor Name:</label> <br />

尝试通过PHP将HTML5表单提交到电子邮件,并在成功提交后重定向到“谢谢!”页面。问题是,表单没有发送,重定向也没有发生

这是我的HTML:

<form id="vendorInfo" action="process_form_vendor.php" method="post">
        <label for="vendorName">Vendor Name:</label>
        <br />              
    <input id="vendorName" name="vendorName" type="text" maxlength="30" required>
    <br />  
        <label for="contactName">Contact Name:</label>                  <br />
    <input id="contactName" name="contactName" type="text" maxlength="35" required>
    <br />
        <label for="vendorType">Organization Type:</label>
        <br />
    <select id="vendorType" name="vendorType">
        <option value="carrier">
            Insurance Carrier
        </option>
        <option value="tech_crm">
            Technology/CRM Management
        </option>
        <option value="leadProvider">
            Lead Provider   
        </option>
        <option value="info_comm">
            Information/Communication
        </option>
        <option value="other">
            Other (please describe below)
        </option>
    </select>
    <br />
        <label for="other1">Other Organization Type:</label>
        <br />
    <input id="other1" name="other1" type="text" maxlength="25">
    <br />
        <label for="email">Email:</label>
        <br />
    <input id="email" name="email" type="email" maxlength="30" required>
    <br />
        <label for="phone">Phone:</label>   
        <br />  
    <input id="phone" name="phone" type="tel" maxlength="12" required placeholder="xxx-xxx-xxxx">
    <br />
        <label for="questions">Any questions or comments? Leave them here:</label>
        <br />
    <textarea id="questions" name="questions" rows="10" maxlength="300"></textarea>
    <br />
    <br />
    <fieldset id="selectionBox">
        <legend id="packageSelect">
            The following sponsorship packages are available for the Sales Summit; contact          <ahref="mailto:email@domain.com”>Amanda</a> for pricing and details: 
        </legend>
            <input type="radio" name="packageSelect" value="Bronze Package" checked>&nbsp;Bronze
            <br />
            <br />
            <input type="radio" name="packageSelect" value="Silver Package">&nbsp;Silver
            <br />
            <br />
            <input type="radio" name="packageSelect" value="Gold Lunch Package">&nbsp;Gold&nbsp;(breakfast; exclusive sponsorship)
            <br />
            <br />
            <input type="radio" name="packageSelect" value="Gold Breakfast Package">&nbsp;Gold&nbsp;(lunch; exclusive sponsorship)
            <br />
            <br />
            <input type="radio" name="packageSelect" value="Gold Trade Show Package">&nbsp;Gold&nbsp;(trade&nbsp;show; exclusive sponsorship)
        </fieldset>
        <br />
    <button type="submit" name="submit">Submit</button>&nbsp;<button type="reset" name="reset">Reset</button>
    <br />
</form>

供应商名称:


联系人姓名:

组织类型:
保险公司 技术/客户关系管理 主要供应商 信息/通信 其他(请在下面描述)
其他组织类型:

电邮:

电话:

有什么问题或意见吗?把它们留在这里:


销售峰会提供以下赞助套餐:;有关定价和详细信息,请联系: 青铜色

银币

金牌(早餐;独家赞助)

金牌(午餐;独家赞助)

金牌(贸易展;独家赞助)
提交重置
这是我的PHP:

<?php

if(!isset($_POST['submit']))
{
    echo "error; you need to submit the form!";
}

$vendorName = $_POST['vendorName'];
$contactName = $_POST['contactName'];
$vendorType = $_POST['vendorType'];
$other1 = $_POST['other1'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$questions = $_POST['questions'];
$packageSelect = $_POST['packageSelect'];

if (empty($vendorName)||(empty($contactName)||(empty($vendorType)||(empty($email)||(empty($phone)||(empty($packageSelect)) {
    echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
    exit;   
}

$email_from = 'email@domain.net';
$email_subject = '2014 SMS Sales Summit - New Vendor Reservation Request';
$email_body = "You have received a new vendor reservation request for the 2014 SMS Sales Summit from $contactName at $vendorName.\n".
              "Vendor Type: $vendorType\n".
            "Other Vendor Type: $other1\n".
            "Email Address: $email\n".
            "Phone Number: $phone\n".
            "Additional Questions: $questions\n".
            "Sponsorship Level: $packageSelect\n".

$to = 'email@domain.net';
$headers = "$email_from \r\n";
$headers .= "Reply-To: $email \r\n";

mail($to,$email_subject,$email_body,$headers);
header('Location: thank-you.html');

?>

将其更改为:

$email_from = 'email@domain.net';
请注意单引号中的差异。美元也一样:

$to = ‘email@domain.net';
将其更改为:

$to = 'email@domain.net';
能否删除
中的
“&”


您还需要在最后一行之后使用
关闭表单

为什么
中的
&
?此外,没有结束标记。

您的
$email\u from
$to
中有语法错误。需要使用
(单引号)或
(双引号)而不是
。请尝试此操作

$email_from = 'email@domain.net';
           ...^                ^....
而不是

$email_from = ‘email@domain.net’;
另外,在您的
if
情况下,您错过了添加大量


您忘了在$email\u body后面加分号

请放一个

$email_body = "";
测试了)试试看,它对我有用



另外,您可能会收到一个错误,说“headers ready sent”,这对我来说是错误的,所以我在结尾使用了一个echo,并对您的
header(“..
进行测试。如果在
错误日志之前有空格?为什么在源代码中有智能引号?发现了反勾号!虽然我见过一些情况,但尝试使用单引号(
)或双引号(
)。我已经修复了PHP中的所有反勾号(我认为这只是我提交问题时的一个失误;我在文本编辑器中打开代码来修复选项卡等,它们在某些地方被转换)然后返回到我的原始代码,以验证它们实际上是勾号而不是智能引号。但是,当我尝试提交表单时,没有任何结果。这一行
if(空($vendorName)|(empty($contactName)|(empty($vendorType)|(empty($email)|(empty($phone)| |(empty($packageSelect))
应读作
if(empty($vendorName)|(contactName)| empty($vendorType)| empty($email)| | | empty($email)| | empty($phone)| | | empty($packageSelect
我已经从按钮类型声明中删除了符号,但当我尝试提交时仍然一无所获。当我在原始问题中输入HTML时,丢失的表单标记是我的一个错误。你在PHP上启用了OpenSSL扩展吗?啊,是的,那些可怕的智能/卷曲引号。“漂亮,但致命。”。“我已经检查并更正了所有的反勾号,但是当我试图提交表单时仍然没有任何结果。所谓的“没有结果”,是指邮件已“发送”但没有变量?还是“没有”发生?@andrewdcato和这一行
“赞助级别:$packageSelect\n”。
应该是
“赞助级别:$packageSelect\n”
结尾有一个点,应该是一个分号@andrewdcato@Fred-ii-抱歉造成混淆-未发送电子邮件,并重定向到“谢谢”页面仍然没有出现。我已从按钮类型声明中删除了符号,但在尝试提交时仍然没有得到任何结果。当我在原始问题中输入HTML时,丢失的表单标记对我来说是一个错误。您确实拥有所需的所有
HTML
head
body
标记和closing标记?是的;我的HTML有效日期没有问题。我已经更正了您指出的所有错误(PHP中的符号和智能引号),但仍然没有。表单根本没有提交。我看到了必需的属性,您是否正确填写了所有字段?@KrishR谢谢您,Krish,非常感谢:)@Fred ii-成功了!电子邮件已成功提交。现在,对于重定向…我需要在最后一行中更改什么才能使其显示我指定的“thank-you.html”页面?您可以尝试添加
ob_start()
就在
的下面,请看我的编辑/重新加载。我把它放在
@Fred ii的下面-非常感谢。你让我的PHP转换变得更容易了:)
$email_from = 'email@domain.net';
           ...^                ^....
$email_from = ‘email@domain.net’;
if (empty($vendorName)||
      empty($contactName)||
         empty($vendorType)||
            empty($email)||
                empty($phone)||
                    empty($packageSelect) ) {
echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
exit;   
}
$email_body = "";
<?php
// uncomment line below to use with header redirect
// ob_start();
if(!isset($_POST['submit']))
{
    echo "error you need to submit the form!";
}


$vendorName = $_POST['vendorName'];
$contactName = $_POST['contactName'];
$vendorType = $_POST['vendorType'];
$other1 = $_POST['other1'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$questions = $_POST['questions'];
$packageSelect = $_POST['packageSelect'];


if (empty($vendorName)|| empty($contactName)|| empty($vendorType)|| empty($email)|| empty($phone)|| empty($packageSelect)){
    echo "Vendor Name, Contact Name, Vendor Type, Email, Phone, and Package Selection are mandatory!";
    exit;   
}

 $email_from = 'email@domain.net';

$email_subject = '2014 SMS Sales Summit - New Vendor Reservation Request';
$email_body = "You have received a new vendor reservation request for the 2014 SMS Sales Summit from $contactName at $vendorName.\n".
              "Vendor Type: $vendorType\n".
            "Other Vendor Type: $other1\n".
            "Email Address: $email\n".
            "Phone Number: $phone\n".
            "Additional Questions: $questions\n".
            "Sponsorship Level: $packageSelect\n";

$to = "email@domain.net";

$headers = 'From: ' . $email_from . "\r\n";

$headers .= "Reply-To: $email \r\n";

mail($to,$email_subject,$email_body,$headers);
// header('Location: thank-you.html');

 echo "thanks";

?>
<button type="submit" name="submit">Submit</button>
<input type="submit" name="submit" value="Submit">