<? $pass = 'fer'; if($Submit) { updatecfg(); } if($show == "$pass" or !is_file('config.php')) { admin_setup(stylevar()); } elseif ($send) { send_email(stylevar()); } else { show_main(stylevar()); } /************************************************************************************/ //MAIN Functions // /************************************************************************************/ // Update config.php file function updatecfg(){ global $title,$bgcolor,$text,$link,$alink,$vlink,$css,$emailtxt,$tellnumber,$subject; $emailtxt = preg_replace("!\r\n!", '#', $emailtxt); $config = fopen('config.php', 'w'); fwrite($config, "title||$title bgcolor||$bgcolor text||$text link||$link alink||$alink vlink||$vlink tellnumber||$tellnumber subject||$subject emailtxt||$emailtxt css||$css"); fclose($config); } // Send email function send_email(&$stylevar){ global $HTTP_POST_VARS; $num=0; while($num < $stylevar[tellnumber]) { $num++; $temail = "address"."$num"; $tname = "name"."$num"; $friend_name = $$tname; $message = preg_replace('!\[friend_name\]!', $HTTP_POST_VARS[$tname], $stylevar[emailtxt]); $message = preg_replace('!\[msag\]!', $HTTP_POST_VARS[msag], $message); $message = preg_replace('!\[from_name\]!', $HTTP_POST_VARS[from_name], $message); if($HTTP_POST_VARS[$temail] AND $HTTP_POST_VARS[$tname]) { mail($HTTP_POST_VARS[$temail],"$stylevar[subject]","$message ---------------------------- ( http://www.comocriarsites.net/ ) ","From: $HTTP_POST_VARS[from_name] <$HTTP_POST_VARS[from_email]>"); } } show_header($stylevar); echo "<br><font size=6 color=red><b> Rcomendações feitas com sucesso, acesse o link abaixo para iniciar o curso!</b></font><br><br><a href=?html=cursoonline1>Iniciar</a><BR><BR><BR>Muito obrigado por ter colaborado, você não vai se arrepender!"; show_footer(); } // Get variables from config.php if present function stylevar(){ if(is_file('config.php')) { $config = file('config.php'); foreach($config as $l){ $l = explode('||', $l); $stylevar[$l[0]] = trim($l[1]); } $stylevar[emailtxt] = stripslashes(preg_replace('!#!', "\r\n", $stylevar[emailtxt])); } else { $stylevar[title] = 'My Website.'; $stylevar[emailtxt] = 'Hi [friend_name],##You will like this site: http://www.cognitivedistortion.com##Message:#[msag]'; $stylevar[emailtxt] = stripslashes(preg_replace('!#!', "\r\n", $stylevar[emailtxt])); } return $stylevar; } /************************************************************************************/ // HTML Functions // /************************************************************************************/ // Show the main page function show_main(&$stylevar){ show_header($stylevar); ?> <form name="form2" method="post" action=""> <table width="400" border="0" align="center"> <td colspan="2" align="center">Seu nome: <input type="text" name="from_name"></td> </tr> <tr> <td colspan="2" align="center">Seu E-mail: <input type="text" name="from_email"></td> </tr> <tr> <td align="center">Nomes dos amigos:</td><td align="center">E-mails dos amigos:</td> </tr> <tr> <? $num = 0; while($num < $stylevar[tellnumber]) { $num++; ?> <td align="center"><input type="text" name="name<?=$num?>"></td><td align="center"><input type="text" name="address<?=$num?>"></td> </tr> <tr> <? } ?> <td colspan="2" align="center">Mensagem: (opcional)<BR><textarea name="msag" cols="45" rows="4"></textarea></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="send" value="Recomendar"></td> </tr> </table> </form> <? show_footer(); } // Show admin page function admin_setup(&$stylevar){ show_header($stylevar); ?> <form name="form1" method="post" action=""> <table width=400 border=0> <tr> <td colspan=2 align=center bgcolor=<?=$stylevar[hlcolor]?>> <Font size=4>Admin setup:</font> </td></tr><tr> <tr> <td colspan=2 align=center> Required fields are marked with a red asterisk (<font color=red>*</font>). </td></tr><tr> <td> <input type="text" name="title" value="<?=$stylevar[title]?>"></td><td><font color=red>*</font> Website Name</tr><tr> <td><input type="text" name="bgcolor" value="<?=$stylevar[bgcolor]?>"></td><td>BG Color</tr><tr> <td><input type="text" name="text" value="<?=$stylevar[text]?>"></td><td>Text Color</tr><tr> <td><input type="text" name="link" value="<?=$stylevar[link]?>"></td><td>Link Color</tr><tr> <td><input type="text" name="vlink" value="<?=$stylevar[vlink]?>"></td><td>vlink Color</tr><tr> <td><input type="text" name="alink" value="<?=$stylevar[alink]?>"></td><td>alink Color</tr><tr> <td><input type="text" name="css" value="<?=$stylevar[css]?>"></td><td>Path to Style sheet</tr><tr> <td><input type="text" name="tellnumber" value="<?=$stylevar[tellnumber]?>"></td><td><font color=red>*</font> Number of mail boxes.</tr><tr> <td><input type="text" name="subject" value="<?=$stylevar[subject]?>"></td><td><font color=red>*</font> Email Subject</tr><tr> <td align=center colspan=2>Enter any defalut message you would like to send:<br><textarea name="emailtxt" cols="55" rows="8"><?=$stylevar[emailtxt]?></textarea></td> <tr> <td align=center colspan=2><input name="Submit" type="submit" value="Submit"> </td> </tr> </table> </form> <? show_footer(); } // Header function show_header(&$stylevar){ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title><?=$stylevar[title]?></title> <link rel="stylesheet" href="<?=$stylevar[css]?>" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="<?=$stylevar[bgcolor]?>" text="<?=$stylevar[text]?>"> <center> <? } // Footer function show_footer(){ ?> </body> </html> <? } ?>
Ele funciona bem, mas eu gostaria que tivesse alguma validação de campos no formulário, para que as pessoas não possam enviar tudo em branco...
O problema é que eu não sei muito de PHP, e gostaria que quem responder a pergunta alterace o código e postasse aqui...
Agradeço muito a quem conseguir....