Notas Técnicas do zhaoJian

Programa PHP para enviar formulário para E-mail

Tecnologia ~8550 palavras · 22 min de leitura - visualizações

Recentemente, durante a reformulação do site, quis criar um programa para enviar formulários online para e-mail. Procurei muitos programas, mas nenhum funcionou, então acabei desenvolvendo um eu mesmo.

<html>
<body>
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['w_14']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['w_14']);
$w_1_check = $_REQUEST['w_1'];
$w_8_check = $_REQUEST['w_8'];
$w_13_check = $_REQUEST['w_13'];
if ($mailcheck==FALSE)
{
echo "<script language=\"JavaScript\">\r\n";
echo " alert(\"Por favor, preencha o E-mail corretamente para que nossa equipe possa entrar em contato com você. Obrigado pela cooperação!\");\r\n";
echo " history.back();\r\n";
echo "</script>";
}
if ($w_1_check=='')
{
echo "<script language=\"JavaScript\">\r\n";
echo " alert(\"Por favor, preencha o nome da empresa corretamente para que nossa equipe possa entrar em contato com você. Obrigado pela cooperação!\");\r\n";
echo " history.back();\r\n";
echo "</script>";
}
if ($w_8_check=='')
{
echo "<script language=\"JavaScript\">\r\n";
echo " alert(\"Por favor, preencha o nome corretamente para que nossa equipe possa entrar em contato com você. Obrigado pela cooperação!\");\r\n";
echo " history.back();\r\n";
echo "</script>";
}
if ($w_13_check=='')
{
echo "<script language=\"JavaScript\">\r\n";
echo " alert(\"Por favor, preencha o número de QQ/MSN corretamente para que nossa equipe possa entrar em contato com você. Obrigado pela cooperação!\");\r\n";
echo " history.back();\r\n";
echo "</script>";
}
else
{//send email
$email = $_REQUEST['w_14'] ;
$subject = $_REQUEST['w_1'] . " " . $_REQUEST['w_8'] ;
$message = "Nome da empresa :". $_REQUEST['w_1'] . "\r\n" . "Idiomas do site :". $_REQUEST['w_2_1'] . "/" . $_REQUEST['w_2_2'] . "/" . $_REQUEST['w_2_3'] . "/" . $_REQUEST['w_2_4'] . "/" . $_REQUEST['w_2_5'] . "/" . "\r\n" . "Sites de referência :". $_REQUEST['w_3'] . "\r\n" . "Descrição do negócio :". $_REQUEST['w_4'] . "\r\n" . "Orçamento para desenvolvimento :". $_REQUEST['w_5'] . "-" . $_REQUEST['w_6'] . "\r\n" . "Prazo de conclusão desejado :". "Data de conclusão desejada" . $_REQUEST['w_7'] . "\r\n" . " Dias para conclusão desejados" . $_REQUEST['w_7_1'] . "\r\n" . "Outros requisitos :". $_REQUEST['w_7_2'] . "\r\n" . "=============================================================" . "\r\n" . "Nome :". $_REQUEST['w_8'] . "\r\n" . "Sexo :". $_REQUEST['w_9'] . "\r\n" . "Telefone :". $_REQUEST['w_11'] . "\r\n" . "Celular :". $_REQUEST['w_12'] . "\r\n" . "QQ/MSN :". $_REQUEST['w_13'] . "\r\n" . "E-mail :". $_REQUEST['w_14'] . "\r\n" . "Skype :". $_REQUEST['w_15'] . "\r\n" . "CEP :". $_REQUEST['w_16'] . "\r\n" . "Endereço :". $_REQUEST['w_17'] . "\r\n";
mail("admin@zhaojian.net", "$subject preencheu o formulário de intenção de desenvolvimento do site.",
$message, "From: $email");
echo "<script language=\"JavaScript\">\r\n";
echo "alert(\"Informações enviadas com sucesso! Por favor, aguarde o contato de nossa equipe. Retornando automaticamente à página inicial.\");\r\n";
echo "location.replace(\"http://www.zhaojian.net/\");\r\n";
echo "</script>";
}
}
else
{//if "email" is not filled out, display the form
echo "<form id='form1' action='http://www.zhaojian.net/b/b.php' method='post' name='form1'>
<table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'>
<tbody>
<tr>
<th colspan='2'>Formulário de Solicitação de Desenvolvimento de Site</th>
</tr>
<tr>
<td class='input_1' width='125'>Nome da Empresa</td>
<td class='input_2' width='550'><input class='input_text' style='width: 300px' name='w_1' type='text' /></td>
</tr>
<tr>
<td class='input_1' width='125'>Idiomas do Site</td>
<td class='input_2' width='550'><input type='checkbox' checked='checked' name='w_2_1' value='Chinês Simplificado' /> <label for='w_2_1'>Chinês Simplificado</label> <input type='checkbox' name='w_2_2' value='Chinês Tradicional' /> <label for='w_2_2'>Chinês Tradicional</label> <input type='checkbox' name='w_2_3' value='Inglês' /> <label for='w_2_3'>Inglês</label> <input type='checkbox' name='w_2_4' value='Japonês' /> <label for='w_2_4'>Japonês</label> <input type='checkbox' name='w_2_5' value='Outros Idiomas' /> <label for='w_2_5'>Outros Idiomas</label></td>
</tr>
<tr>
<td class='input_1' width='125'>Sites de Referência</td>
<td class='input_2' width='550'><input style='width: 300px' name='w_3' type='text' /></td>
</tr>
<tr>
<td class='input_1' width='125'>Descrição do Negócio</td>
<td class='input_2' width='550'><textarea class='input_text' style='width: 300px' name='w_4'></textarea></td>
</tr>
<tr>
<td class='input_1' width='125'>Orçamento para Desenvolvimento</td>
<td class='input_2' width='550'><input class='input_text' name='w_5' type='text' /> -- <input class='input_text' name='w_6' type='text' /> yuan</td>
</tr>
<tr>
<td class='input_1' width='125'>Prazo de Conclusão Desejado</td>
<td class='input_2' width='550'><input class='input_text' name='w_7' value='Data de conclusão desejada' type='text' /> <input class='input_text' name='w_7_1' value='Dias para conclusão desejados' type='text' /> dias</td>
</tr>
<tr>
<td class='input_1' width='125'>Outros Requisitos</td>
<td class='input_2' width='550'><textarea class='input_text' style='width: 300px' name='w_7_2'></textarea></td>
</tr>
</tbody>
</table>
<table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'>
<tbody>
<tr>
<th colspan='4'>Informações de Contato</th>
</tr>
<tr>
<td class='input_1' width='129'>Nome</td>
<td class='input_2' width='202'><input name='w_8' type='text' /></td>
<td class='input_1' width='96'>Sexo</td>
<td class='input_2' width='246'><input type='radio' checked='checked' name='w_9' value='Sra.' />Sra. <input type='radio' name='w_9' value='Sr.' />Sr.</td>
</tr>
<tr>
<td class='input_1' align='left'>Telefone</td>
<td class='input_2'><input class='input_text' name='w_11' type='text' /></td>
<td class='input_1'>Celular</td>
<td class='input_2'><input name='w_12' type='text' /></td>
</tr>
<tr>
<td class='input_1'>QQ / MSN</td>
<td class='input_2'><input class='input_text' name='w_13' type='text' /></td>
<td class='input_1'>E-mail</td>
<td class='input_2'><input name='w_14' type='text' /></td>
</tr>
<tr>
<td class='input_1'>Skype</td>
<td class='input_2'><input class='input_text' name='w_15' type='text' /></td>
<td class='input_1'>CEP</td>
<td class='input_2'><input name='w_16' type='text' /></td>
</tr>
<tr>
<td class='input_1'>Endereço</td>
<td class='input_2'><input name='w_17' type='text' /></td>
<td class='input_1'>Endereço da Empresa</td>
<td class='input_2'><input name='w_172' type='text' /></td>
</tr>
</tbody>
</table>
<table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'>
<tbody>
<tr>
<td class='input_2'>
<div align='center'><input id='send_mail_agent' type='submit' name='w_18' value='Submit' /></div>
</td>
</tr>
</tbody>
</table>
</form>";
}
?>
</body>
</html>
Compartilhar:

Comentários