Co treba urobit aby to fungovalo? prosim o radu
Kód:
<?
$rec_file = "contacts.txt";
$rec = file($rec_file);
function getContacts($rec) {
foreach($rec as $line) {
list($cnumber, $cname, $cemail, $cdept) = split(";", $line);
echo '<option value="'.$cnumber.'">'.$cdept.' -> '.$cname.'</option>'."\n";
}
}
if(!isset($_POST['do'])) {
echo '
<b>Select a contact</b><p>
<form name="contact" method="post" action="'.$PHP_SELF.'">
<select name="contacts">';
getContacts($rec);
echo '</select>
<br />
<b>´Meno:</b><br><input type="text" name="sender"><br>
<b>E-mail:</b><br><input type="text" name="email"><br>
<b>Váš text:</b><br><textarea name="message"></textarea><br>
<input type="hidden" name="do" value="sendmail">
<input type="submit" value="Send" />
</form>';
} else {
foreach($rec as $line) {
$number = $_POST['contacts'];
list($cnumber, $cname, $cemail, $cdept) = split(";", $line);
if($cnumber == $number) {
$contname = $cname;
$contemail = $cemail;
}
}
$sender_name = $_POST['sender'];
$sender_email = $_POST['email'];
$sender_msg = $_POST['message'];
$headers = "Od: ".$sender_name." <".$sender_email."> \r\n";
$headers.= "Content-Type: text/plain; charset=windows-1250 ";
$headers .= "MIME-Version: 1.0 ";
$email_subject = "Nová správa od: ".$sender_name;
$mail_text = '
Hello '.$contname.'
'.$sender_name.' is sending you the following message:
----------------------------------------------------------
'.$sender_msg.'
----------------------------------------------------------
Tento e-mail vám zaslal '.$sender_email;
mail($contemail, $email_subject, $mail_text, $headers);
echo '<b>Ďakujeme!</b><p>S pozdravom '.$contemail.'.';
}
?>