Hey mensen,
Ben bezig om voor 't eerst een xhtml 1.0 strict validated webbased programma te maken.. tot dus ver 2/2 gelukt.
Helaas werkt de mail functie van de contact pagina wél, alleen de html krijg ik niet binnen.
Ook heb ik meerdere afzenders ingesteld, maar ik krijg het mailtje maar 1x binnen ( ik vul altijd mn 2e email adress in als ik 'm test. )
Kan iemand even kijken waarom het zootje niet werkt?
Alvast bedankt ;D
(Beetje wall of text idee.. maargoed.. : ) )
Hier en daar wat gecensored, vooral website links en email adressen.
Tips zijn enorm welkom!
Groetjes,
Simolokid
Ben bezig om voor 't eerst een xhtml 1.0 strict validated webbased programma te maken.. tot dus ver 2/2 gelukt.
Helaas werkt de mail functie van de contact pagina wél, alleen de html krijg ik niet binnen.
Ook heb ik meerdere afzenders ingesteld, maar ik krijg het mailtje maar 1x binnen ( ik vul altijd mn 2e email adress in als ik 'm test. )
Kan iemand even kijken waarom het zootje niet werkt?
Alvast bedankt ;D
(Beetje wall of text idee.. maargoed.. : ) )
PHP:
<?php
session_start();
/* Email address where the messages should be delivered */
$to = 'mailadress1';
/* From email address, in case your server prohibits sending emails from addresses other than those of your
own domain (e.g. email@yourdomain.com). If this is used then all email messages from your contact form will appear
from this address instead of actual sender. */
$from = 'noreply@......';
/* This will be appended to the subject of contact form message */
$subject_prefix = 'some_prefix';
/* Empty/Invalid fields will be highlighted in this color */
$field_error_color = '#FF0000';
/* URL to be redirected to after the form is submitted. If this is specified, then the above message will
not be shown and user will be redirected to this page after the form is submitted */
/* Example: $thank_you_url = 'http://www.yourwebsite.com/thank_you.html'; */
$thank_you_url = 'some_url_here';
/*******************************************************************************
* Do not change anything below, unless of course you know very well
* what you are doing :)
*******************************************************************************/
$name = array('Name','name',NULL,NULL);
$email = array('Email','email',NULL,NULL,NULL);
$subject = array('Subject','subject',NULL,NULL);
$message = array('Message','message',NULL,NULL);
$code = array('Code','captcha_code',NULL,NULL,NULL);
$error_message = '';
if (!isset($_POST['submit'])) {
showForm();
} else { //form submitted
$error = 0;
if(!empty($_POST['name'])) {
$name[2] = clean_var($_POST['name']);
if (function_exists('htmlspecialchars')) $name[2] = htmlspecialchars($name[2], ENT_QUOTES);
}
else {
$error = 1;
$name[3] = 'color:#FF0000;';
}
if(!empty($_POST['email'])) {
$email[2] = clean_var($_POST['email']);
if (!validEmail($email[2])) {
$error = 1;
$email[3] = 'color:#FF0000;';
$email[4] = '<strong><span style="color:#FF0000;">Email is not valid.</span></strong>';
}
}
else {
$error = 1;
$email[3] = 'color:#FF0000;';
}
if(!empty($_POST['subject'])) {
$subject[2] = clean_var($_POST['subject']);
if (function_exists('htmlspecialchars')) $subject[2] = htmlspecialchars($subject[2], ENT_QUOTES);
}
else {
$error = 1;
$subject[3] = 'color:#FF0000;';
}
if(!empty($_POST['message'])) {
$message[2] = clean_var($_POST['message']);
$length = strlen($message[2]);
if($length < 300){
if (function_exists('htmlspecialchars')){
$message[2] = htmlspecialchars($message[2], ENT_QUOTES);
}
else{
$error = 1;
$message[3] = 'color:#FF0000;';
}
}
else {
$error = 1;
$message[4] = '<strong><span style="color:#FF0000;">The message may only contain 300 characters.</span></strong>';
$message[3] = 'color:#FF0000;';
}
if($length > 10){
if (function_exists('htmlspecialchars')){
$message[2] = htmlspecialchars($message[2], ENT_QUOTES);
}
else{
$error = 1;
$message[3] = 'color:#FF0000;';
}
}
else {
$error = 1;
$message[4] = '<strong><span style="color:#FF0000;">The message has to contain atleast 10 characters.</span></strong>';
$message[3] = 'color:#FF0000;';
}
}
else{
$error = 1;
$message[4] = '<strong><span style="color:#FF0000;">You have not filled in a message.</span></strong>';
$message[3] = 'color:#FF0000;';
}
if(empty($_POST['captcha_code'])) {
$error = 1;
$code[3] = 'color:#FF0000;';
} else {
include_once "securimage.php";
$securimage = new Securimage();
$valid = $securimage->check($_POST['captcha_code']);
if(!$valid) {
$error = 1;
$code[3] = 'color:#FF0000;';
$code[4] = '<strong><span style="color:#FF0000;">Code is incorrect.</span></strong>';
}
}
if ($error == 1) {
$error_message = '<span style="font-weight:bold;font-size:90%;">Please fill in or correct the fields in red.</span>';
showForm();
} else {
if (function_exists('htmlspecialchars_decode')) $name[2] = htmlspecialchars_decode($name[2], ENT_QUOTES);
if (function_exists('htmlspecialchars_decode')) $subject[2] = htmlspecialchars_decode($subject[2], ENT_QUOTES);
if (function_exists('htmlspecialchars_decode')) $message[2] = htmlspecialchars_decode($message[2], ENT_QUOTES);
$message = "$name[0]: $name[2]\r\n$email[0]: $email[2]\r\n\r\n$message[0]:\r\n$message[2]\r\n";
if (!$from) $from_value = $email[2];
else $from_value = $from;
$headers = "From: $from_value" . "\r\n" . "Reply-To: $email[2]";
// multiple recipients
$to = 'mailadress_1' . ', '; // note the comma
$to .= $_POST['email']; //second email
// subject
$subject = 'Contact-form';
$msg = $_POST['message'];
// message
$message = '
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>some_title</title>
<link rel="stylesheet" type="text/css" href="admin_style.css" />
</head>
<body>
<div id="_bk_"><img class="background" src="admin_media/admin_images/bk.png" alt="" /></div>
<div id="site">
<div id="header"><img src="admin_media/admin_images/header.png" alt="" title="" /></div>
<div id="exit">
<div id="log_out">Quit</div>
</div>
<div id="fc"></div>
<div id="menu">
<div class="menu_item"><strong>Welcome</strong></div>
<div class="menu_item">Question-Tour</div>
<div class="menu_item">Conclusion</div>
<div class="menu_item">Walktrough<br />
<em>Your back-end system</em></div>
<div class="menu_item"></div>
<div class="menu_item"></div>
<div class="menu_item"></div>
<div class="menu_item"></div>
<div class="menu_item_time">Estimated time:<br />
15 minutes</div>
<div class="menu_item"></div>
</div>
<div id="content">
<div id="title_welcome">Contact-message</div>
<br />
<br />
$msg
</div>
</div>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$email_sender = $_POST['email'];
// Additional headers
$headers .= 'To: '.$email_sender.'' . "\r\n";
$headers .= 'From: mail_1' . "\r\n";
$headers .= 'Cc: mail_2' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
if (!$thank_you_url) {
}
else {
header("Location: $thank_you_url");
}
}
} //else submitted
function showForm()
{
global $name, $email, $subject, $message, $code;
$something = $GLOBALS['error_message'];?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>- Contact</title>
<link rel="stylesheet" type="text/css" href="admin_style.css" />
</head>
<body>
<div id="_bk_"><img class="background" src="admin_media/admin_images/bk.png" alt="" /></div>
<div id="site">
<div id="header"><img src="admin_media/admin_images/header.png" alt="" title="" /></div>
<div id="exit">
<div id="log_out">Quit</div>
</div>
<div id="fc"></div>
<div id="menu">
<div class="menu_item"><strong>Welcome</strong></div>
<div class="menu_item">Question-Tour</div>
<div class="menu_item">Conclusion</div>
<div class="menu_item">Walktrough<br />
<em>Your back-end system</em></div>
<div class="menu_item"></div>
<div class="menu_item"></div>
<div class="menu_item"></div>
<div class="menu_item"></div>
<div class="menu_item_time">Estimated time:<br />
15 minutes</div>
<div class="menu_item"></div>
</div>
<div id="content"><div id="title_welcome">Contact Me.</div><br />
<?php echo "<form action=\"\" method=\"post\" class=\"cForm\">
<table>
<tr>
<td style=\"$name[3]\">$name[0]</td>
<td><input type=\"text\" name=\"$name[1]\" value=\"$name[2]\" /></td>
</tr>
<tr>
<td style=\"$email[3]\">$email[0]</td>
<td><input type=\"text\" name=\"$email[1]\" value=\"$email[2]\" /> $email[4]</td>
</tr>
<tr>
<td style=\"$subject[3]\">$subject[0]</td>
<td><input type=\"text\" name=\"$subject[1]\" value=\"$subject[2]\" size=\"40\" /></td>
</tr>
<tr>
<td style=\"$message[3]\">$message[0]</td>
<td><textarea name=\"$message[1]\" cols=\"40\" rows=\"6\">$message[2]</textarea><br />$message[4]</td>
</tr>
<tr>
<td> </td>
<td><img id=\"captcha\" src=\"securimage_show.php\" alt=\"CAPTCHA Image\" /></td>
</tr>
<tr>
<td style=\"$code[3]\">$code[0]</td><td><input type=\"text\" name=\"$code[1]\" size=\"10\" maxlength=\"5\" /> $code[4]</td>
</tr>
<tr>
<td></td><td style=\"text-align: right;\"><input type=\"submit\" name=\"submit\" value=\"Send\" /></td>
</tr>
</table>
</form>
<div id=\"next_button\">Next Step >></div>
</div>
</div>
</body>
</html>
";
}
function clean_var($variable) {
$variable = strip_tags(stripslashes(trim(rtrim($variable))));
return $variable;
}
/**
Email validation function. Thanks to http://www.linuxjournal.com/article/9585
*/
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && function_exists('checkdnsrr'))
{
if (!(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
// domain not found in DNS
$isValid = false;
}
}
}
return $isValid;
}
?>
Hier en daar wat gecensored, vooral website links en email adressen.
Tips zijn enorm welkom!
Groetjes,
Simolokid