Contact formulier > Email checker! [hulp nodig!]
Beste,
Ik wil graag een contact script voor mijn website..
ik heb er een gevonden! maar zonder mail checker...
ik heb een mailcheck script gedownload en erin gezet,
alleen werkt hij niet :S
Live preview: http://tinyurl.com/7skakzt
De contact script bestaad uit 4 paginas:
- index.php
- functions.php
- captcha.php
- config.php
index.php:
Functions:
Het mail script werkt nu niet.. ,
Alvast bedankt!
Ik wil graag een contact script voor mijn website..
ik heb er een gevonden! maar zonder mail checker...
ik heb een mailcheck script gedownload en erin gezet,
alleen werkt hij niet :S
Live preview: http://tinyurl.com/7skakzt
De contact script bestaad uit 4 paginas:
- index.php
- functions.php
- captcha.php
- config.php
index.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/** start sessions **/
@session_start();
/** include config **/
include('config.php');
/** include functions email **/
include('functions_email.php');
/** reset error & success vars **/
$error = 0;
$success = 0;
$error_message = '';
/** set error message array **/
$error_message = array();
/** try to send message **/
if(isset($_POST['submit']))
{
/** check if name is filled in **/
if($_POST['name'] == '')
{
$error = 1;
$error_message[] = 'Please fill in your full name.';
}
/** check if email is filled in **/
if($_POST['email'] == '')
{
$error = 1;
$error_message[] = 'Please enter a valid email.';
}
elseif(ControleerEmail($_POST['email'])) {
$error = 1;
$error_message[] = 'controleer je email';
}
/** check if subject is filled in **/
if($_POST['subject'] == '')
{
$error = 1;
$error_message[] = 'Please enter a subject.';
}
/** check if comment is filled in **/
if($_POST['comments'] == '')
{
$error = 1;
$error_message[] = 'Please write a comment.';
}
/** check if captcha is correct **/
if($_POST['Captcha'] != $_SESSION['Captcha'] || $_POST['Captcha'] == '')
{
$error = 1;
$error_message[] = 'Please choose the correct captcha.';
}
/** no error **/
if($error != 1)
{
send_generic($mailto, $_POST['email'], $_POST['subject'], $_POST['comments']);
if($autorespond == true){ send_generic($_POST['email'], $mailto, 'RE: '.$_POST['subject'], $autorespond_message); }
$success = 1;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
#contact {background: #fff; border: 1px solid #e7e7e7; margin: 30px auto 1em; text-align: left; width: 400px; padding: 2em; margin-bottom: 30px;}
#contact #error {background: #f9efef url(images/cross.png) no-repeat 9px 8px; width: auto; height: auto; padding: 9px 34px; color: #494949; font: 11px arial; border: 1px #e9c6c6 solid; margin-bottom: 20px;}
#contact #success {background: #DFF2BF url(images/tick.png) no-repeat 9px 8px; width: auto; height: 13px; padding: 9px 34px; color: #4F8A10; font: 11px arial; border: 1px #4F8A10 solid;}
#contact .clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
#contact hr {border: 0px; background: none; border-bottom: 1px dotted #aaa; height: 0px; margin: 1em 0;}
#contact label {display: block; margin-bottom: 4px; color: #6182a1;}
#contact input[type=text], #contact input[type=password], #contact textarea {color: #333; margin-bottom: 7px; background: #fff; border: 1px solid #ccc; padding: 5px; width: 95%;}
#contact input[type=submit] {background: #eee; border: 3px double #ccc; padding: 2px; font-size: 1em; width: auto; margin-right: 6px;}
#contact a {color: #6182a1; font: inherit; text-decoration: none;}
#contact #captcha div {display: inline; float: left;}
</style>
<script type="text/javascript" src="./javascript/jquery.js"></script>
<script type="text/javascript" src="./javascript/captcha.js"></script>
<title>SpiralContact</title>
</head>
<body>
<div id="contact" class="clearfix">
<?php
if($error == 1)
{
echo '<div id="error">';
foreach($error_message as $err){ echo $err . "<br>"; }
echo '</div>';
}
?>
<?php if($success != 1): ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="name">Name</label>
<input name="name" id="name" size="30" type="text" value="<?php echo $_POST['name']; ?>" />
<label for="email">Email</label>
<input name="email" id="email" size="30" type="text" value="<?php echo $_POST['email']; ?>" />
<label for="subject">Subject</label>
<input name="subject" id="subject" size="30" type="text" value="<?php echo $_POST['subject']; ?>" />
<label for="comments">Comments</label>
<textarea name="comments" cols="46" rows="5" id="comments"><?php echo $_POST['comments']; ?></textarea>
<div id="captcha"><?php require('captcha.php'); ?></div><br /><br />
<hr>
<input name="submit" value="Submit" type="submit" />
</form>
<?php else: ?>
<div id="success">Thank you for your comments.</div>
<?php endif; ?>
</div>
</body>
</html>
/** start sessions **/
@session_start();
/** include config **/
include('config.php');
/** include functions email **/
include('functions_email.php');
/** reset error & success vars **/
$error = 0;
$success = 0;
$error_message = '';
/** set error message array **/
$error_message = array();
/** try to send message **/
if(isset($_POST['submit']))
{
/** check if name is filled in **/
if($_POST['name'] == '')
{
$error = 1;
$error_message[] = 'Please fill in your full name.';
}
/** check if email is filled in **/
if($_POST['email'] == '')
{
$error = 1;
$error_message[] = 'Please enter a valid email.';
}
elseif(ControleerEmail($_POST['email'])) {
$error = 1;
$error_message[] = 'controleer je email';
}
/** check if subject is filled in **/
if($_POST['subject'] == '')
{
$error = 1;
$error_message[] = 'Please enter a subject.';
}
/** check if comment is filled in **/
if($_POST['comments'] == '')
{
$error = 1;
$error_message[] = 'Please write a comment.';
}
/** check if captcha is correct **/
if($_POST['Captcha'] != $_SESSION['Captcha'] || $_POST['Captcha'] == '')
{
$error = 1;
$error_message[] = 'Please choose the correct captcha.';
}
/** no error **/
if($error != 1)
{
send_generic($mailto, $_POST['email'], $_POST['subject'], $_POST['comments']);
if($autorespond == true){ send_generic($_POST['email'], $mailto, 'RE: '.$_POST['subject'], $autorespond_message); }
$success = 1;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
#contact {background: #fff; border: 1px solid #e7e7e7; margin: 30px auto 1em; text-align: left; width: 400px; padding: 2em; margin-bottom: 30px;}
#contact #error {background: #f9efef url(images/cross.png) no-repeat 9px 8px; width: auto; height: auto; padding: 9px 34px; color: #494949; font: 11px arial; border: 1px #e9c6c6 solid; margin-bottom: 20px;}
#contact #success {background: #DFF2BF url(images/tick.png) no-repeat 9px 8px; width: auto; height: 13px; padding: 9px 34px; color: #4F8A10; font: 11px arial; border: 1px #4F8A10 solid;}
#contact .clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
#contact hr {border: 0px; background: none; border-bottom: 1px dotted #aaa; height: 0px; margin: 1em 0;}
#contact label {display: block; margin-bottom: 4px; color: #6182a1;}
#contact input[type=text], #contact input[type=password], #contact textarea {color: #333; margin-bottom: 7px; background: #fff; border: 1px solid #ccc; padding: 5px; width: 95%;}
#contact input[type=submit] {background: #eee; border: 3px double #ccc; padding: 2px; font-size: 1em; width: auto; margin-right: 6px;}
#contact a {color: #6182a1; font: inherit; text-decoration: none;}
#contact #captcha div {display: inline; float: left;}
</style>
<script type="text/javascript" src="./javascript/jquery.js"></script>
<script type="text/javascript" src="./javascript/captcha.js"></script>
<title>SpiralContact</title>
</head>
<body>
<div id="contact" class="clearfix">
<?php
if($error == 1)
{
echo '<div id="error">';
foreach($error_message as $err){ echo $err . "<br>"; }
echo '</div>';
}
?>
<?php if($success != 1): ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="name">Name</label>
<input name="name" id="name" size="30" type="text" value="<?php echo $_POST['name']; ?>" />
<label for="email">Email</label>
<input name="email" id="email" size="30" type="text" value="<?php echo $_POST['email']; ?>" />
<label for="subject">Subject</label>
<input name="subject" id="subject" size="30" type="text" value="<?php echo $_POST['subject']; ?>" />
<label for="comments">Comments</label>
<textarea name="comments" cols="46" rows="5" id="comments"><?php echo $_POST['comments']; ?></textarea>
<div id="captcha"><?php require('captcha.php'); ?></div><br /><br />
<hr>
<input name="submit" value="Submit" type="submit" />
</form>
<?php else: ?>
<div id="success">Thank you for your comments.</div>
<?php endif; ?>
</div>
</body>
</html>
Functions:
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
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
<?php
/** this function sends a custom email **/
function send_generic($recipient, $sender, $subject, $message, $search = "", $replace = "")
{
/** decode subject and email for sending **/
$subject = htmlspecialchars_decode($subject, ENT_QUOTES);
$message = htmlspecialchars_decode($message, ENT_QUOTES);
/** replace variables in subject and message **/
$subject = str_replace($search, $replace, $subject);
$message = str_replace($search, $replace, $message);
/** encode subject for UTF8 **/
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
/** replace carriage returns with breaks **/
$message = str_replace("\n", "<br>", $message);
/** set headers **/
$headers = "MIME-Version: 1.0"."\n";
$headers .= "Content-type: text/html; charset=utf-8"."\n";
$headers .= "Content-Transfer-Encoding: 8bit"."\n";
$headers .= "From: $sender"."\n";
$headers .= "Return-Path: $sender"."\n";
$headers .= "Reply-To: $sender";
/** send mail **/
mail($recipient, $subject, $message, $headers);
return true;
}
function ControleerEmail($a)
{
return ereg("[A-Za-z0-9_-]+([\.]{1}[A-Za-z0-9_-]+)*@[A-Za-z0-9-]+([\.]{1}[A-Za-z0-9-]+)+",$a);
}
?>
/** this function sends a custom email **/
function send_generic($recipient, $sender, $subject, $message, $search = "", $replace = "")
{
/** decode subject and email for sending **/
$subject = htmlspecialchars_decode($subject, ENT_QUOTES);
$message = htmlspecialchars_decode($message, ENT_QUOTES);
/** replace variables in subject and message **/
$subject = str_replace($search, $replace, $subject);
$message = str_replace($search, $replace, $message);
/** encode subject for UTF8 **/
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
/** replace carriage returns with breaks **/
$message = str_replace("\n", "<br>", $message);
/** set headers **/
$headers = "MIME-Version: 1.0"."\n";
$headers .= "Content-type: text/html; charset=utf-8"."\n";
$headers .= "Content-Transfer-Encoding: 8bit"."\n";
$headers .= "From: $sender"."\n";
$headers .= "Return-Path: $sender"."\n";
$headers .= "Reply-To: $sender";
/** send mail **/
mail($recipient, $subject, $message, $headers);
return true;
}
function ControleerEmail($a)
{
return ereg("[A-Za-z0-9_-]+([\.]{1}[A-Za-z0-9_-]+)*@[A-Za-z0-9-]+([\.]{1}[A-Za-z0-9-]+)+",$a);
}
?>
Het mail script werkt nu niet.. ,
Alvast bedankt!
Gewijzigd op 11/01/2012 17:52:22 door Chris -
Zoiezo zie ik al dat er
Code graag tussen code-tags.
Hoe weet je zeker dat het mailscript niet werkt? Gaat het niet eerder fout? Krijg je een foutmelding?
Ereg is verouderd. Kijk naar pregmatch
PHP_SELF wordt afgeraden. Gebruik bv action=""
Ik blijf adviseren om niet op de mailfunctie van php te vertrouwen, maar bv swiftmailer of phpmailer te gebruiken.
Gebruik geen if(isset($_POST['submit'])) maar if($_SERVER['REQUEST_METHOD'] == "POST")
om te controleren of een formulier is verzonden.
Waarom een @ voor session_start();
Hoe weet je zeker dat het mailscript niet werkt? Gaat het niet eerder fout? Krijg je een foutmelding?
Ereg is verouderd. Kijk naar pregmatch
PHP_SELF wordt afgeraden. Gebruik bv action=""
Ik blijf adviseren om niet op de mailfunctie van php te vertrouwen, maar bv swiftmailer of phpmailer te gebruiken.
Gebruik geen if(isset($_POST['submit'])) maar if($_SERVER['REQUEST_METHOD'] == "POST")
om te controleren of een formulier is verzonden.
Waarom een @ voor session_start();
Gewijzigd op 11/01/2012 17:18:45 door Obelix Idefix
Ibrahim A op 11/01/2012 17:04:10:
... script voor mijn website ...
ik heb er een gevonden! ...
alleen werkt hij niet :S
ik heb er een gevonden! ...
alleen werkt hij niet :S
Misschien kan je beter een script zoeken dat wel werkt.
Wanneer mensen een script maken en een specifiek probleem hebben, helpen we met plezier.
Maar hier heb je een kant-en-klaar script; en het werkt niet. We zien onmiddellijk dat er verouderde technologie in zit (bv. ereg() ).
Hoi Ibrahim,
Ik heb je post even aangepast en de code in de -tags geplaatst. Dat is een stuk beter te kijken.
Je functie ControleerEmail is verouderd. Je kan beter gebruik maken van filter_var, en dat gebruiken!
Laat even horen of het nu wel werkt :)
Als het nog niet werkt, kijk dan ook even of je nog foutmeldingen heb en plaats die dan hier.
Groeten,
Chris
Ik heb je post even aangepast en de code in de -tags geplaatst. Dat is een stuk beter te kijken.
Je functie ControleerEmail is verouderd. Je kan beter gebruik maken van filter_var, en dat gebruiken!
Laat even horen of het nu wel werkt :)
Als het nog niet werkt, kijk dan ook even of je nog foutmeldingen heb en plaats die dan hier.
Groeten,
Chris




