简体   繁体   English

电子邮件表格未发送

[英]Email form not sending

I"m having trouble getting this email form to submit. The email.php file is in the root directory and looks like this: 我无法提交此电子邮件表单。email.php文件位于根目录中,如下所示:

<?php
 $val= $_POST['val'];
 $toemail='someone@gmail.com';
 $name = $val['name'];
 $email = $val['email'];
 $msg = $val['msg'];

$subject = 'Message from zachjanice.com';

$headers = "From: zachjanice.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

&nbsp;

$message = "<b>Name :</b>".$name."<br>";
$message .='<b>Email :</b>'.$email."<br>";
$message .='<b>Message :</b>'.$msg;
mail($toemail, $subject, $message, $headers);

echo "Thanks for contacting me!";

?>

I'm using validate.js to validate the form and bootstrap to style. 我正在使用validate.js来验证表单并引导至样式。 Here is the HTML: 这是HTML:

<form class="contactform" role="form">
                    <div class="form-group">
                        <label class="control-label">Name</label>
                        <div class="controls">
                            <div class="input-group">
                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                <input type="text" class="form-control" name="name" placeholder="Name">
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">Email</label>
                        <div class="controls">
                            <div class="input-group">
                            <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
                                <input type="text" class="form-control" id="email" name="email" placeholder="Email">
                            </div>
                        </div>  
                    </div>

                    <div class="form-group ">
                        <label class="control-label">Message</label>
                        <div class="controls">
                            <div class="input-group">
                            <span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
                                <textarea name="msg" class="form-control " rows="4" cols="78" placeholder="Enter your message here"></textarea>

                            </div>
                        </div>
                    </div>

                    <div class="controls" style="margin-left: 40%;">

                        <button type="submit" id="mybtn" class="btn btn-primary">Send Message</button>

                    </div>
            </form>

I forgot here is my JS: 我忘了这里是我的JS:

$(document).ready(function(){
 $.validator.setDefaults({
submitHandler: function(form) {
 $.ajax({
 type: "POST",
 url: "email.php",
 data: { 'val':$(".contactform").serializeJSON() }
 }).done(function(data) {
 alert(data);

 });
 }
});
$(".contactform").validate(
{rules:
{name:"required",
email:{required:true,email:true},
website:{required:false,url:true},
cate:"required",
msg:{required:true, maxlength:300
}},
errorClass:"error",
highlight: function(label) {
 $(label).closest('.form-group').removeClass('has-success').addClass('has-error');
 },

success: function(label) {
 label
 .text('Seems Perfect!').addClass('valid')
 .closest('.form-group').addClass('has-success');
 }
});
});

Help is greatly appreciated. 非常感谢您的帮助。 I'm trying to get this site done tonight if possible, but I'm a little flustered at this point. 如果可能的话,我正在努力今晚完成此站点,但此时我有点慌张。

Try to var_dump(mail($toemail, $subject, $message, $headers)); 尝试var_dump(mail($toemail, $subject, $message, $headers));

You'll get some useful info. 您会获得一些有用的信息。

Also check if vars $name, $email and $msg are populated, if not do it like this: $name = $_POST['name'] 还要检查是否填充了变量$name, $email$msg ,如果不这样做,则这样: $name = $_POST['name']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM