javascript - Email form not sending -
i"m having trouble getting email form submit. email.php file in root directory , looks this:
<?php $val= $_post['val']; $toemail='someone@gmail.com'; $name = $val['name']; $email = $val['email']; $msg = $val['msg']; $subject = 'message 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"; $message = "<b>name :</b>".$name."<br>"; $message .='<b>email :</b>'.$email."<br>"; $message .='<b>message :</b>'.$msg; mail($toemail, $subject, $message, $headers); echo "thanks contacting me!"; ?>
i'm using validate.js validate form , bootstrap style. here 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 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 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 appreciated. i'm trying site done tonight if possible, i'm little flustered @ point.
try var_dump(mail($toemail, $subject, $message, $headers));
you'll useful info.
also check if vars $name, $email
, $msg
populated, if not this: $name = $_post['name']
Comments
Post a Comment