Contact Forum
Ik ben nog niet zo gek lang met Php/html bezig dus ik zie de fout niet.
Misschien jullie wel?
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
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['email'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );
$from = $_POST['email'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}
?>
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
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
<!-- form -->
<script type="text/javascript" src="js/form-validation.js"></script>
<form id="contactForm" action="#" method="post">
<h2 class="heading">Contact us using this form</h2>
<p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget.</p>
<fieldset>
<div>
<input name="name" id="name" type="text" class="form-poshytip" title="Enter your full name" />
<label>Name</label>
</div>
<div>
<input name="email" id="email" type="text" class="form-poshytip" title="Enter your email address" />
<label>Email</label>
</div>
<div>
<input name="web" id="web" type="text" class="form-poshytip" title="Enter your website" />
<label>Website</label>
</div>
<div>
<textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
</div>
<!-- send mail configuration -->
<input type="hidden" value="[email protected]" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">The mail has been send. Thanks, someone of the crew will answer as soon as possible</p>
<!-- ENDS form -->
<script type="text/javascript" src="js/form-validation.js"></script>
<form id="contactForm" action="#" method="post">
<h2 class="heading">Contact us using this form</h2>
<p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget.</p>
<fieldset>
<div>
<input name="name" id="name" type="text" class="form-poshytip" title="Enter your full name" />
<label>Name</label>
</div>
<div>
<input name="email" id="email" type="text" class="form-poshytip" title="Enter your email address" />
<label>Email</label>
</div>
<div>
<input name="web" id="web" type="text" class="form-poshytip" title="Enter your website" />
<label>Website</label>
</div>
<div>
<textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
</div>
<!-- send mail configuration -->
<input type="hidden" value="[email protected]" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>
</form>
<p id="sent-form-msg" class="success">The mail has been send. Thanks, someone of the crew will answer as soon as possible</p>
<!-- ENDS form -->
Gewijzigd op 10/09/2013 13:41:35 door Robin Lokate
Ik zou er zeker geen mailadres neerzetten (spambots).
Hidden fields zie je niet op het scherm, ze staan wel in je broncode en zijn dus aan te passen.
Controleren of een formulier verzonden is:
Waarom kopieer je variabelen (regel 4-7)?
Verwacht je meerdere e-mailadresen bij $_POST['to']?
Je controleert niet of alle velden gevuld zijn.
Je controleert niet of het mailadres wel een mailadres kan zijn.
Je neemt zonder enige beveiliging de $_POST waarden op in het mailbericht.
Kijk naar phpmailer of swiftmailer om mails te versturen. De mailfunctie van php (b)lijkt lastig goed te gebruiken.