带有PHP发件人的网站表单不会发送电子邮件

时间:2016-05-11 19:19:45

标签: php forms email

我一直试图通过网站表单提交来发送电子邮件。我确保邮件命令有效,所以我不知道我做错了什么。请帮忙。提前谢谢!

我已经被发送到stackoverflow上的其他PHP提交代码,它仍然无法正常工作。

HTML代码:

 <form action="/includes/support_form.php" form id="support_form" method="POST">
                        <div class="form-group">
                            <label>
                                Name
                            </label>
                            <input id="name" class="form-control" type="text" name="name" required />
                        </div>
                        <div class="form-group">
                            <label>
                                Email
                            </label>
                            <input id="email" class="form-control" type="email" name="email" required />
                        </div>
                        <div class="form-group">
                            <label>
                                Company Name
                            </label>
                            <input id="company" class="form-control" type="text" name="company" required />
                        </div>
                        <div class="form-group">
                            <label>
                                Phone Number
                            </label>
                            <input id="phone" class="form-control" type="text" name="phone" required />
                        </div>
                        <div class="form-group">
                            <label>
                                About Your Business
                            </label><textarea id="message" class="form-control" rows="4" cols="50" name="message" required></textarea>
                        </div>
                        <div class="form-group">
                            <label>
                                Please Contact me by
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="radioSetOne" value="option1" id="input_342" />Email
                            </label>
                        </div>
                        <div class="radio">
                            <label>
                                <input type="radio" name="radioSetOne" value="option2" id="input_2152" />Phone
                            </label>
                        </div>
                        <button class="bloc-button btn btn-lg btn-block btn-sea-green" type="submit">
                            Submit
                        </button>
                    </form>

这是我必须收集数据并发送电子邮件的support_form.php文件。

<?php   
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['company']) || empty($_POST['phone']) || empty($_POST['message']) || empty($_POST['input_342']) || empty($_POST['input_2152']))
{
    return false;
}

$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$input_342 = $_POST['input_342'];
$input_2152 = $_POST['input_2152'];

$to = 'xxxx@gmail.com'; // Email submissions are sent to this email

// Create email 
$email_subject = "Message from My Site.";
$email_body = "You have received a new message. \n\n".
              "Name: $name \nEmail: $email \nEmail: $email \nEmail: $email \nMessage: $message \nInput_342: $input_342 \nInput_2152: $input_2152 \n";
$headers = "From: xxxx@gmail.com\n";
$headers .= "Reply-To: $email"; 

mail($to,$email_subject,$email_body,$headers); // Post message
return true; ?>

0 个答案:

没有答案