Scripts
Contact script , Swift-Mailer
Ik had even tijd en had voor jullie een contact script gemaakt. Omdat er hier heel veel personen een mailing script hebben waarbij header injection mogelijk is Ik hoop dat jullie hier iets mee kunnen Verbeteringen en tips altijd welkom Download swiftmailer: Download link Demo: Demo
contact.php
[code]
<!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" xml:lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<title>contact script</title>
</head>
<body>
<?php
//instellingen
$email_host = ''; //mail.bedrijf.nl
$email_naam = ''; //admin , bedrijf
$email_adres = ''; // [email protected]
$website = ''; // website url
$ban = array('0.0.0.0', '0.0.0.0', '0.0.0.0' ); // ban een IP , meer IP'S toevoegen kan door ,'' toetevoegen
if (in_array($_SERVER['REMOTE_ADDR'], $ban, true)) {
echo "Verbannen via IP";
} else {
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$error = array();
if($_POST['naam'] == '') {
$error[0] = TRUE;
}
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])\?*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email'])) {
$error[1] = TRUE;
}
if($_POST['onderwerp'] == '') {
$error[2] = TRUE;
}
if($_POST['bericht'] == '') {
$error[3] = TRUE;
}
if( !isset($error ) ) {
//SWIFTMAILER
require_once 'lib/swift_required.php';
$mailer = new Swift_Mailer(new Swift_SmtpTransport($email_host));
$message = Swift_Message::newInstance($_POST['onderwerp'], 'Verstuurd vanaf het contact form op '.$website.' <br /><br />Van het ipadres: '.$_SERVER['SERVER_ADDR'].'<br />bericht:<br /><br />'.nl2br(htmlentries($_POST['bericht'])))
->setFrom(array($_POST['email'] => $_POST['naam']))
->setTo(array($email_adres => $email_naam))
->setContentType('text/html');
$mailer->send($message);
$title = 'Er is succesvol een email gestuurd!';
$text = 'Bedankt , Uw email is verzonden<br />Uw bericht zal gelezen worden en zo spoedig mogelijk worden beantwoord.';
}
}
if($title) {
Echo '<h1>'.$title.'</h1><br /><br />';
} Else {
Echo '<h1>Contact</h1>';
}
if($text) {
Echo $text;
} else {
if($error) {
Echo '<font color=#ff0000><b>Er is iets misgegaan , Check de velden in het rood!<br /></b></font>';
}
?>
<form method="post" action=''>
<table border="0" cellpadding="0" cellspacing="10">
<tr>
<td width="161" valign="top">
<strong>Naam:</strong>
</td>
<td width="477">
<input name="naam" OnKeyPress="this.style.cssText='border: 2px solid black;'" type="text" style="border: 2px solid
<?php if($error[0]) { Echo 'red'; }else { Echo 'black'; } ?>;" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>E-mail adres:</strong>
</td>
<td>
<input name="email" OnKeyPress= "this.style.cssText='border:2px solid black;'" type="text" style="border: 2px solid
<?php if($error[1]) { Echo 'red'; }else { Echo 'black'; } ?>;" value="" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Onderwerp:</strong>
</td>
<td>
<input name="onderwerp" OnKeyPress= "this.style.cssText='border: 2px solid black;'" type="text" style="border: 2px solid
<?php if($error[2]) { Echo 'red'; }else { Echo 'black'; } ?>;" value="" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Bericht:</strong>
</td>
<td>
<textarea name="bericht" cols="50" rows="10" OnKeyPress="this.style.cssText='border: 2px solid black;'" style="border: 2px solid
<?php if($error[3]) { Echo 'red'; }else { Echo 'black'; } ?>;" ></textarea>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="submit" type="submit" value="Verstuur" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
}
?>
[/code]
Reacties
0