发送邮件功能以通过表单提交无效

时间:2016-02-06 10:15:42

标签: php forms phpmailer

我不确定是什么问题,但在提交表单时它不会发送电子邮件。以下是代码:

if (isset ($_POST['business_name']) && isset ($_POST['business_address']) && isset ($_POST['business_city']) && isset ($_POST['business_email'])) {

$business_name = $_POST['business_name'];
$business_address = $_POST['business_address'];
$business_city = $_POST['business_city'];
$business_email = $_POST['business_email'];

if (!empty($business_name) && !empty($business_address) &&!empty($business_city) && !empty($business_email))  {

$to = 'myemail@gmail.com'; 
$subject = 'New Submission From mywebsite.com';
$body = $business_name. "\n" . $business_address. "\n" . $business_city .          "\n" . $business_email;
$headers = "From:" . $business_email;

    if (@mail ($to, $subject, $body, $headers)) 

            }

        }


    ///i think everything is there but could be wrong im a beginner         

<form action="emailtest.php" method="POST">
<input id="busines_name" type="text" placeholder="Business Name" required>   <br />
<input id="business_address" type="text" placeholder="Business Address"   required><br />
<input id="business_city" type="text" placeholder="Business City & State" required><br />
<input id="business_email" type="email" placeholder="Your Email Address" required><br />
<input type="submit"value="SUBMIT">
</form>

1 个答案:

答案 0 :(得分:2)

为所有字段更改输入

<input id="busines_name" name="busines_name" type="text" placeholder="Business Name" required>   <br />

您需要使用name选项才能使其正常工作