Contactformulier geeft errormelding na aanpassing
Ik ben op dit moment met een website bezig en heb gebruik gemaakt van een bootstrap template (http://startbootstrap.com/template-overviews/freelancer/).
Daar zat al een werkend contactformulier in en deze wil ik graag uitbreiden met wat extra velden.
Originele code:
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
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
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Bericht vanaf de website: $name";
$email_body = "Je hebt een bericht ontvangen via de website!\n\n"."Lees snel verder:\n\nNaam: $name\n\nE-mailadres: $email_address\n\nTelefoonnummer: $phone\n\nBericht:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Bericht vanaf de website: $name";
$email_body = "Je hebt een bericht ontvangen via de website!\n\n"."Lees snel verder:\n\nNaam: $name\n\nE-mailadres: $email_address\n\nTelefoonnummer: $phone\n\nBericht:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Wat ik er zelf van heb gemaakt:
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
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
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['adress']) ||
empty($_POST['zip']) ||
empty($_POST['town']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$adress = $_POST['adress'];
$zip = $_POST['zip'];
$town = $_POST['town'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Bericht vanaf de website: $name";
$email_body = "Je hebt een bericht ontvangen via de website!\n\n"."Lees snel verder:\n\nNaam: $name\n\nAdres: $adress\n\nPostcode: $zip\n\nPlaats: $town\n\nE-mailadres: $email_address\n\nTelefoonnummer: $phone\n\nBericht:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['adress']) ||
empty($_POST['zip']) ||
empty($_POST['town']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$adress = $_POST['adress'];
$zip = $_POST['zip'];
$town = $_POST['town'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Bericht vanaf de website: $name";
$email_body = "Je hebt een bericht ontvangen via de website!\n\n"."Lees snel verder:\n\nNaam: $name\n\nAdres: $adress\n\nPostcode: $zip\n\nPlaats: $town\n\nE-mailadres: $email_address\n\nTelefoonnummer: $phone\n\nBericht:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
In het html formulier heb ik de extra velden ook toegevoegd.
Er wordt nu helaas geen mail verstuurd, hebben jullie een idee?
Mvg,
Frits
Gewijzigd op 03/04/2016 11:55:58 door Frits Folkerts
http://phpwiki.santhe.nl/index.php?title=De_juiste_mailheaders
Verder is een controle op je mail() functie of deze gelukt is (true/false) ook zeker niet overbodig.
Overigens is het "address", niet "adress".