Hi all,
I'm building a website where are zip code are important. Based on the zip code the contact form is redirected to an email adress. So I live in Holland where we have 12 provinces, and based on the zip code you can know where somebody lives, lets say you has zip code: 5233HS You live in Noord-Brabant. Then it sends the email to somebody there. But if you got a zip code in another province, the mail is forwarded to another email adress in that province. I was thinking about a Javascript which compare all zip code's until it found one that's equal. Or is there a solution simpeler?
And how to do it with javascript or another method.
I done something in php but it won't work.
if (isset($_POST['submit'])) {
function random_strings($length_of_string)
{
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
return substr(str_shuffle($str_result), 0, $length_of_string);
}
$Output = random_strings(10);
$conn = mysqli_connect("localhost", "...", "...", "...");
if($conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$Zip = $_POST['Zip'];
$name = $_POST['Name'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Subject = $_POST['Problem'];
$Zip = $_POST['Zip'];
$Subject = $_POST['Problem'];
$txt1 = "Noord-Holland";
$arr1 = range(1000,1299);
$txt2 = "Flevoland";
$arr2 = range(1300,1379);
if ($arr1 == $Zip) {
$mailTo = "info@probleeminhuis.nl";
mail($mailTo, $txt1, $Subject, $Zip);
}
elseif ($arr2 == $Zip) {
$mailTo = "info@probleeminhuis.nl";
mail($mailTo, $txt2, $Subject, $Zip);
}
if ($stmt = mysqli_prepare($conn, "INSERT INTO ID (Id, Name, Email, Phone, Problem, Zip) VALUES (?, ?, ?, ?, ?, ?)")) {
mysqli_stmt_bind_param($stmt, "ssssss", $Output, $name, $Email, $Phone, $Subject, $Zip);
if (mysqli_stmt_execute($stmt)) {
echo ' ';
echo "<div id=\"PHP-output\"> Succesvol Verstuurd </div>";
} else{
echo ' ';
echo "<div id=\"PHP-output\"> Sorry, Het kon niet worden verstuurd, probeer het later nog eens of neem contact op met de klantenservice. $sql. </div>" . mysqli_error($conn);
}
}
mysqli_close($conn);
And the origin of the variables:
<pre> <form action="../../PHP/Ticketnumber.php" method="POST">
<input style="width: 90%;" type="text" name="Name" placeholder="Volledige naam">
<input style="width: 90%;" type="text" name="Email" placeholder="E-mail">
<input style="width: 90%;" type="text" name="Phone" placeholder="Telefoon">
<input style="width: 90%;" type="text" name="Zip" placeholder="Postcode">
<input style="width: 90%;" type="text" name="Problem" placeholder="Omschrijf je probleem zo simpel mogelijk">
<button style="margin-bottom: 10px" class="button-probleem" type="submit" name="submit">Verzenden</button>
<p>Als je op verzenden drukt ga je akkoord met de <a style="text-decoration: underline; cursor: pointer;" href="../../Algemene-voorwaarden.html">algemene voorwaarden!</a></p>
</form>
It don't send an email.
Improved code where elseif is not working:
<pre>
$name = $_POST['Name'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Subject = $_POST['Problem'];
$Zip = $_POST['Zip'];
if ($Zip > 999 && $Zip < 1300) {
$Zip = $_POST['Zip'];
$txt1 = "Noord-Holland";
$mailTo = "";
mail($mailTo, $txt1, $Subject, $Zip);
}
elseif ($Zip > 1299 && $Zip < 1380) {
$txt2 = "Flevoland";
$Zip = $_POST['Zip'];
$mailTo = "";
mail($mailTo, $txt2, $Subject, $Zip);
}
Thanks, Sam
What I have tried:
I tried to code in PHP. Ans searched google.