Jump to content

My First PHP Mail Form and my errors


Sunamena
 Share

Recommended Posts

Hello everyone!

This is my very first PHP document, and i must admit, i have no experience or knowledge about PHP, i looked at an example and tryd to connect the dots to create this one. It works better than expected, but I do encounter a few issues, where I would very much like to have some advise with.

Problem 1: The data from the form gets mailed to me, but even though everything in the form is filled in, I would only receive the
"E-mail: INPUT@HOTMAIL.COM"
The rest of the data like:
"Meetnaam: "
Were blank, as if the data did not exist.
The form did check correctly wether this information was provided, but seems not to provide so in the e-mail send to me.

Problem 2: $meetnaam should be the subject of the e-mail.

Problem 3: $email should also be the e-mail adress asigned to the sender, as such, I can easily reply.

 

Problem 4: The checkbox, $akkoord, should be checked, if not, an error should be displayed, I do not know how to do this.

 

 

 

Your help with this problem is very much apreciated! :good:
Once again: I am new to this, so try to be very specific (if you would even be so kind, type it out and put the update in bold text) =D

 

This is the PHP and HTML code I used respectively:



PHP

 


<?php
/* Set e-mail recipient, WORKS */
$myemail = "support@nimblefeather.com";
/* Check all form inputs using check_input function, WORKS */
$name = check_input($_POST['meetnaam'], "Voer de meet naam in.");
$subject = check_input($_POST['meetadres'], "Voer het adres van de meet in.");
$email = check_input($_POST['email']);
/* If e-mail is not valid show error message, WORKS */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Het opgegeven e-mail adres is ongeldig.");
}
/* Let's prepare the message for the e-mail, ERROR */
$message = "
Naam van de meet: $meetnaam
Organisator: $organisator
Adres: $meetadres
Binnen of buiten: $binbuit
E-mail adres: $email
Mag e-mail verschijnen op de website: $emailtonen
Contact (telefoon): $telefoon
Uren: $meeturen
Bereikbaarheid met de trein: $trein
Bereikbaarheid met de auto: $auto
Andere informatie: $andereinfo
Akkoord met de regels: $akkoord
";
/* Send the message using mail() function, $myemail WORKS, $meetnaam should be the Topic but isn't, $message is displayed, yet only partly */
mail($myemail, $meetnaam, $message);
/* Redirect visitor to the thank you page, WORKS */
header('Location: klaar.html');
exit();
/* Functions used, WORKS */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Oeps, verbeter alstublieft de volgende fout:</p>
<strong><?php echo $myError; ?></strong>
<p>Keer terug, en probeer het opnieuw.</p>
</body>
</html>
<?php
exit();
}
?>

 

 

 

 

 

 

 

 

 

 

 

HTML

 

 

 

 

 

 

<form method="post" action="meetmailer.php">
<div class="colformwrap">
<div class="colformleft">
Naam van de meet <span class="verplicht">*</span>:
</div><!--
--><div class="colformright">
<input type="text" name="meetnaam" maxlength="50">
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Naam van de organisatie of organisator:
</div><!--
--><div class="colformright">
<input type="text" name="organisator" maxlength="50">
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Adres van de meet <span class="verplicht">*</span>:
</div><!--
--><div class="colformright">
<input type="text" name="meetadres" maxlength="50">
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Is de meet binnen of buiten?
</div><!--
--><div class="colformright">
<select name="binbuit">
<option value="Buiten">Buiten</option>
<option value="Binnen">Binnen</option>
<option value="Binnen en Buiten">Binnen en Buiten</option>
</select>
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Contact (e-mail adres) <span class="verplicht">*</span>:
</div><!--
--><div class="colformright">
<input type="text" name="email" maxlength="50">
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Mag dit e-mail adres op de website verschijnen?
</div><!--
--><div class="colformright">
<input class="bolleke" type="radio" name="emailtonen" value="0" checked> Neen <input class="bolleke" type="radio" name="emailtonen" value="1"> Ja
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Contact (telefoon):
</div><!--
--><div class="colformright">
<input type="text" name="telefoon" maxlength="50">
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Uren:
</div><!--
--><div class="colformright">
<input type="text" name="meeturen" maxlength="50">
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Bereikbaarheid met de trein:
</div><!--
--><div class="colformright">
<textarea name="trein" maxlength="5000"></textarea>
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Bereikbaarheid met de auto:
</div><!--
--><div class="colformright">
<textarea name="auto" maxlength="5000"></textarea>
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
Andere informatie:
</div><!--
--><div class="colformright">
<textarea name="andereinfo" maxlength="5000"></textarea>
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
 
</div><!--
--><div class="colformright">
<input class="bolleke" type="checkbox" name="akkoord" value="0"> Ik heb de <a href="#">regels</a> gelezen en ga hiermee akkoord.
</div>
</div>
<div class="colformwrap">
<div class="colformleft">
 
</div><!--
--><div class="colformright">
<input class="verstuurknop" type="submit" value="Verzenden">
</div>
</div>
</form>

 

 

 

 

Link to comment
Share on other sites

Were blank, as if the data did not exist.

They don't exist? Because everything but the email variable has value applied to it

$email = check_input($_POST['email']);

The rest are empty waiting for a value to be applied to them. Every value that is retrieved from form uses $_POST['form_name_attribute_value']; this retrieved value is applied to appropriate variable. Those that are probably fixed and set by you such as subject are applied as a string value representing the subject of email to subject variable, before the message variable.

  • Like 1
Link to comment
Share on other sites

I understand now.


I now receive all of the data, and my biggest problem is solved.


How wonderfull!


New question: Can i make certain text bold in the message? (i tried <b></b> but it didn't work.

Problem still existing: How to check with PHP if the "akkoord" checkbox is checked?

 

Problem still existing: I can't find how to assign the senders e-mail adress as the sender.
mail($myemail, $meetnaam, $message);
Where do i fit in $email in that function? I always seem to get an error whenever i do so.

 

 

 

Thanks in advance =D
And thanks again for your beuatifull explaination! =D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...