用于向我的Gmail发送电子邮件的网站表单

时间:2016-01-26 10:29:00

标签: php twitter-bootstrap email

所以,在这里,我有这个引导表单,我想从我的gmail帐户发送票证。

这是我的HTML

<form name="sentMessage" id="contactForm" novalidate action="mail/contact.php" method="post" >
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="tel" class="form-control" placeholder="Your Phone " id="phone">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-lg-12 text-center">
                            <div id="success"></div>
                            <button type="submit" class="btn btn-xl">Send Message</button>
                        </div>
                    </div>
                </form>

这是我的php没有工作,之后我在上面的html中包含了action,method和enctype类。

<?php   //check empty fields
if(empty($_POST['name'])        || 
empty($_POST['email'])      ||
empty($_POST['message'])    ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

$to = 'myemail@gmail.com'; 
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website                 contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:              

$email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; //No email on the host, tried postmark inbound email address but no go.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

提前谢谢

2 个答案:

答案 0 :(得分:0)

最好不要使用mailto:在您的表单操作中,用户不会正确配置它并且无法正常工作。而不是mailto使用你的PHP脚本的地址,也使用method =&#34; post&#34;。

要在php中实际发送电子邮件,您需要使用邮件功能(它们是更好的解决方案,但更复杂)。

您可以在http://www.tutorialspoint.com/php/php_sending_emails.htm找到简单的教程。您可以跳过配置部分,因为它应该已经在大多数服务器上设置。

答案 1 :(得分:0)

  

$ to ='myemail@gmail.com;

你没有关闭你的字符串。它应该是这样的:

$to = 'myemail@gmail.com';