PHP contact formulier probleem
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:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?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__));
}
?>
/* ========================== 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__));
}
?>
[email protected] niet kunnen mailen, volgens je reguliere expressie, die maar 3 tekens in de extentie toestaat.
Zie ook: https://www.w3schools.com/php/php_form_url_email.asp
Let er ook op dat mensen met een mailadres zoals Zie ook: https://www.w3schools.com/php/php_form_url_email.asp
En wat doet examples.com daar?
PHP: Is dit internationaal of verkrachten we onze mooie Nederlandse taal?
HTML:
Het is e-mail niet email
Afkortingen eidigen met een punt "Min. 5 characters"
Nederlands en Engels door elkaar
Voor het sturen van e-ail zou ik eens kijken nara een api zoals phpmailer.
Kijk ook eens naar https://onzetaal.nl/taaladvies/telefoonnummers-noteren#:~:text=Dus%3A%20netnummer%2C%20streepje%20(met,spatie%3A%2003%20456%2078%2090.
Jan
En via die mailheaders kan iemand ook ontvangers toevoegen.
kortom: je form gebruiken om spam te versturen.
Alexander Smith op 18/12/2021 11:23:00:
Ik ben bezig met een site waarbij het contact formulier niet schijnt te werken.
[..]
Dit is de code:
[..]
Dit is de PHP:
[..]
Dit is de code:
[..]
Dit is de PHP:
En wij zijn geen werknemers. Heb je ergens een vraag over?
Gewijzigd op 02/02/2022 10:35:09 door - Ariën -