auch ich bin absolut unerfahren im Umgang mit php. Ich nutze ein kleines Tell A Friend-Script und habe dort das Rechen-Captcha eingebaut. Es funktioniert auch, doch bekomme ich jetzt nicht mehr die global errors des eigentlichen Scripts ausgegeben (wenn jemand eine ungültige E-Mail einträgt usw.).
Auch weiß ich nicht, wo ich die else-Schleife einbauen kann. Habe alles Mögliche versucht, doch jedesmal wird dann sofort "Der Sicherheitscode ist falsch" ausgegeben.
Das Script nutzt nur die tell_a_friend.php und ein thankyou.html.
Hier der Code:
- Code: Alles auswählen
<?php
session_start();
function encrypt($string, $key) {
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
$sicherheits_eingabe = encrypt($_POST["sicherheitscode"], "256gtr676");
$sicherheits_eingabe = str_replace("=", "", $sicherheits_eingabe);
if(isset($_SESSION['rechen_captcha_spam']) AND $sicherheits_eingabe == $_SESSION['rechen_captcha_spam']){
unset($_SESSION['rechen_captcha_spam']);
/******************************************************************************
* Tell A Friend Script:
* This script allows your visitors to sent invitation to their friends via email to visit your site.
*
* Usage:
* The script comes with three files tell_a_friend.php, thankyou.html and install.txt
* You're NOT allowed to redistribute or sell this script.
* You are allowed to modify this script for your own personal use.
* Please see install.txt attached in the zip for installation instructions.
*
* Notes:
* If you like this script or used it for your website or project.
* Please remember too link back to www.php-learn-it.com.
* Your help is always appreciated.
*
* author: webdev (php-learn-it.com (or phplearnit.com)
* Visit www.php-learn-it.com (or www.phplearnit.com) for more script and tutorials on PHP.
*****************************************************************************/
//minimum characters allowed in the message box
$msg_min_chars = "10";
//maximum characters allowed in the message box
$msg_max_chars = "250";
$errors = array();
function validate_form_items()
{
global $msg_min_chars, $msg_max_chars;
$msg_chars = "{".$msg_min_chars.",".$msg_max_chars."}";
$form_items = array(
"name" => array(
"regex" => "/^([a-zA-Z '-]+)$/",
"error" => "Dein Name ist nicht korrekt",
),
"email" => array(
"regex" =>
"/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/",
"error" => "E-Mail Adresse ist ungültig",
),
"message" => array(
"regex" => "/.*/",
"error" => "Deine Nachricht ist entweder zu kurz oder enthält mehr als $msg_max_chars Zeichen",
),
);
global $errors;
if(!preg_match($form_items["name"]["regex"], $_POST["your_name"]))
$errors[] = $form_items["name"]["error"];
if(!preg_match($form_items["email"]["regex"], $_POST["your_email"]))
$errors[] = "your ".$form_items["email"]["error"];
if(!preg_match($form_items["email"]["regex"], $_POST["friend_email1"]))
$errors[] = "Friend 1 ".$form_items["email"]["error"];
if(strlen(trim($_POST["message"])) < $msg_min_chars || strlen(trim($_POST["message"])) > $msg_max_chars )
$errors[] = $form_items["message"]["error"];
if(trim($_POST["friend_email2"]) != "")
{
if(!preg_match($form_items["email"]["regex"], $_POST["friend_email2"]))
$errors[] = "Friend 2 ".$form_items["email"]["error"];
}
if(trim($_POST["friend_email3"]) != "")
{
if(!preg_match($form_items["email"]["regex"], $_POST["friend_email3"]))
$errors[] = "Friend 3 ".$form_items["email"]["error"];
}
return count($errors);
}
function email($from, $from_name, $to, $message)
{
//header("Location: thankyou.html");return;
$headers .= "from: ".$from."\r\n";
$headers .= "Content-type: text/plain; charset=ISO-8859-1";
$your_domain_name = "www.xyz.de";
//edit what you want your vistors to see in their email here
$subject = $from_name." hat diese Seite $your_domain_name endeckt";
$your_message = "Hallo!\r\n";
$your_message.= ucfirst($from_name);
$your_message.= " sagt: schau doch mal auf diese Seite $your_domain_name - die gefällt Dir bestimmt auch!\r\n";
$your_message.= "Hier ist noch eine Nachricht vom Absender:\n\r";
$message=$your_message.stripslashes($message);
if (mail($to,$subject,$message,$headers) ) {
return true;
} else {
return false;
}
}
function print_error($errors)
{
foreach($errors as $error)
{
$err.=$error."<br/>";
}
echo
"<div style=\"border:1px red solid; font-size:14px; font-weight:normal; color:red; margin:10px; padding:10px;\">
$err
<div>";
}
function form_process()
{
$from_name = $_POST["your_name"];
$from_email = $_POST["your_email"];
$to = $_POST["your_email"].",".$_POST["friend_email1"].",".$_POST["friend_email2"].",".$_POST["friend_email3"];
$message = $_POST["message"];
$error_count = validate_form_items();
if($error_count == 0)
{
if(email($from_email, $from_name, $to, $message))
header("Location: thankyou.html");
else
{
global $errors;
$errors[] = "E-Mail konnte nicht versendet werden. <br>Bitte gib dem Webmaster eine Nachricht über diesen Fehler.";
}
}
}
if(isset($_POST["submit"]))
form_process();
}
?>
<html>
<title>php-learn-it.com - Email Form Script</title>
<head>
</head>
<body bgcolor="#FFFFF0">
<form id="test" method="post" action="<?php echo $PHP_SELF?>" >
<table border="0">
<tr>
<td colspan="2" style="border-bottom:1px solid black;">
<font size="+2"><b>Tell A Friend</b></font>
<br>Wenn Ihnen diese Seite gefällt, erzählen Sie Ihren Freunden davon ...
</td>
</tr>
<tr>
<td colspan="2">
<?php
global $errors;
if(count($errors) != 0){
print_error($errors);
}
?>
</td>
</tr>
<tr>
<td>
<b>Ihr Name:*</b>
</td>
<td>
<b>Ihre E-Mail:*</b>
</td>
</tr>
<tr>
<td>
<input type="text" name="your_name" id="name" size="20" maxlength="25" value="<?php echo $_POST["your_name"]?>">
</td>
<td>
<input type="text" name="your_email" id="email" size="31" maxlength="80" value="<?php echo $_POST["your_email"]?>">
</td>
</tr>
<tr>
<td colspan="2">
<b>Empfänger E-Mail:</b>*<br/>
<input type="text" name="friend_email1" id="name" size="56" maxlength="80" value="<?php echo $_POST["friend_email1"]?>">
</td>
</tr>
<tr>
<td colspan="2">
<b>Empfänger E-Mail:</b><br/>
<input type="text" name="friend_email2" id="name" size="56" maxlength="80" value="<?php echo $_POST["friend_email2"]?>">
</td>
</tr>
<tr>
<td colspan="2">
<b>Empfänger E-Mail:</b><br/>
<input type="text" name="friend_email3" id="name" size="56" maxlength="80" value="<?php echo $_POST["friend_email3"]?>">
</td>
</tr>
<tr>
<td>
<b>Nachricht:*</b>
</td>
<td>
<i>(max 250 Zeichen sind erlaubt)</i>
</td>
</tr>
<tr>
<td colspan="2">
<textarea name="message" id="message" cols="42" rows="5"><?php echo $_POST["message"]?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
Bitte Sicherheitscode eintragen
<br><img src="rechen-captcha.php">
<input type="text" name="sicherheitscode" size="5">
<br><i>(* erforderliche Angaben)</i> <input type="submit" value="Senden" name="submit" >
</td>
</tr>
</table>
</form>
</body>
</html>
Über einen Hinweis wäre ich sehr dankbar!
Liebe Grüße
Ingo[/code]
