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


Website form to send email to my gmail

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

这是我的网页

<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 中包含操作、方法和 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;            
?>

提前谢谢你

$to = 'myemail@gmail.com;

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

$to = 'myemail@gmail.com'; 

最好不要使用 mailto:在您的表单操作中,用户无法正确配置它并且无法正常工作就足够了。不要使用 mailto 使用 php 脚本的地址,还要使用 method="post"。

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

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