Hi,
Ik ben bezig met een site waarbij het contact formulier niet schijnt te werken.
Het mailadres werkt (alles is nieuw) maar voor zover wordt er vanaf het formulier niets naar het opgegeven mailadres gestuurd. Wel van mailadres naar mailadres...niet vanaf contactformulier.
Dit is de code:
<!-- contact-form-section
================================================== -->
<section class="contact-form-section">
<div class="container-fluid">
<div class="contact-form-box">
<form method="post" action="#" id="contact-form" role="form">
<h2>Neem gerust contact op</h2>
<p>Wij beantwoorden binnen 24 uur</p>
<div class="form-group control-group controls">
<input type="text" class="form-control" placeholder="naam" id="name" required data-validation-required-message="We weten graag wie u bent">
<p class="help-block"></p>
</div>
<div class="form-group control-group controls">
<input type="email" class="form-control" placeholder="Email" id="email" required data-validation-required-message="Hoe kunnen wij u bereiken?">
<p class="help-block"></p>
</div>
<div class="form-group control-group controls">
<textarea rows="10" class="form-control" placeholder="Uw bericht" id="message" required data-validation-required-message="Schrijf hier u bericht" minlength="5" data-validation-minlength-message="Min 5 characters" maxlength="999"></textarea>
<p class="help-block"></p>
</div>
<div id="success"> </div>
<!-- For success/fail messages -->
<button type="submit" class="btn btn-main btn-round">Send</button>
</form>
<div class="image-holder">
<img src="upload/others/contact.jpg" alt="">
</div>
</div>
</div>
</section>
<!-- End contact-form section -->
---------------------------------------------------------------------------------------
Dit is de PHP:
<?php
/* ========================== Define variables ========================== */
#Your e-mail address
define("__TO__", "[email protected]");
#Message subject
define("__SUBJECT__", "examples.com = From:");
#Success message
define('__SUCCESS_MESSAGE__', "Your message has been sent. Thank you!");
#Error message
define('__ERROR_MESSAGE__', "Error, your message hasn't been sent");
#Messege when one or more fields are empty
define('__MESSAGE_EMPTY_FILDS__', "Please fill out all fields");
/* ======================== End Define variables ======================== */
//Send mail function
function send_mail($to,$subject,$message,$headers){
if(@mail($to,$subject,$message,$headers)){
echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__));
} else {
echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__));
}
}
//Check e-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}
//Get post data
if(isset($_POST['name']) and isset($_POST['mail']) and isset($_POST['comment'])){
$name = $_POST['name'];
$mail = $_POST['mail'];
$subject = $_POST['subject'];
$comment = $_POST['comment'];
if($name == '') {
echo json_encode(array('info' => 'error', 'msg' => "Please enter your name."));
exit();
} else if($mail == '' or check_email($mail) == false){
echo json_encode(array('info' => 'error', 'msg' => "Please enter valid e-mail."));
exit();
} else if($comment == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your message."));
exit();
} else {
//Send Mail
$to = __TO__;
$subject = __SUBJECT__ . ' ' . $name;
$message = '
<html>
<head>
<title>Mail from '. $name .'</title>
</head>
<body>
<table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Name:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $name .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">E-mail:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $mail .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Subject:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $subject .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Comment:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $comment .'</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $mail . "\r\n";
send_mail($to,$subject,$message,$headers);
}
} else {
echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FILDS__));
}
?>
1.890 views