Send the form to different addresses according to zip code

Asked

Viewed 33 times

0

I have a form that calculates the delivery rate according to the zip code, until then everything works 100%. My client is opening his business in another area and wants the orders to be sent according to the area.

Today all orders are sent to a single email, ordered [email protected], now with the new restaurant in Cusco he wants the orders made with the CEP of Opacabana, be sent to the e-mail requested [email protected]. How can I do that?

Follow the code of the mail.php file

   <?

// Verifica se contagem.php existe
/* Se for a primeira vez que executa ele não irá existir. */
if( file_exists('contagem.php')){
    // Se existir inclui a variavel que armazena a informação
    include('contagem.php');
}

// Salva o proximo número no contagem.php (apagando a informação anterior e salvando o proximo número).
file_put_contents('contagem.php', '<?php $contagem='.((int)$contagem+1).' ?>');

// Exibe o $gerador que é igual a $contagem.
/* Remova o echo para ocultar obviamente */
echo $gerador = (int)$contagem;

?> 

<?php
include "login_senha.php";

$login = $_SESSION['login_usuario'];

$sql = mysql_query("SELECT * FROM usuarios WHERE email = '$email'");
while($linha = mysql_fetch_array($sql)) {
    $nome = $linha['nome'];
    $endereco = $linha['endereco'];
    $cep = $linha['cep'];
    $telefone = $linha['telefone'];
    $email = $linha['email'];
}

date_default_timezone_set('America/Sao_Paulo');
$Agora = date('H:i:s');
$HoraServico = date('H:i:s', strtotime('+69 minute', strtotime($Agora)));


if ( $Agora < '11:00:00'){
    $HoraServico = '12:00:00';
}

else if ( $Agora > '11:00:00' ){
    $HoraServico == $HoraServico;

};

$m = $_POST["mensagem"];
$data = $_POST["data"];
$nome = $_POST['nome'];
$email = $_POST['email'];
$cep = $_POST['cep'];
$endereco = $_POST['endereco'];
$telefone = $_POST['telefone'];
$pagamento = $_POST["pagamento"];
$troco = $_POST["troco"];
$mtotal = $_POST["mtotal"];
$nop = $_POST["nop"];
$op = $_POST["op"];
$obsfruta = $_POST["obsfruta"];
$quentes = $_POST["quentes"];
$molhos = $_POST["molhos"];
$embalagem = $_POST["embalagem"];
$saladas = $_POST["saladas"];
$sopas = $_POST["sopas"];
$sobremesas = $_POST["sobremesas"];
$sucos = $_POST["sucos"];
$bebidas = $_POST["bebidas"];
$emporio = $_POST["emporio"];
$entrega = $_POST["taxadeentrega"];

$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Bardana</title>';

$message .= '<style type="text/css">body, #bodyTable{height:100% !important; margin:0; padding:0; width:100% !important;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;color:#000000;font-weight:normal;}table{border-collapse:collapse;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;}img, a img{border:0; outline:none; text-decoration:none;height:auto; line-height:100%;}a{text-decoration:none !important;}.ReadMsgBody{width:100%;} .ExternalClass{width:100%;}.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div{line-height:100%;}table, td{mso-table-lspace:0pt; mso-table-rspace:0pt;}#outlook a{padding:0;}img{-ms-interpolation-mode: bicubic;display:block;outline:none; text-decoration:none;}body, table, td, p, a, li, blockquote{-ms-text-size-adjust:100%; -webkit-text-size-adjust:100%; font-weight:normal!important;}.ExternalClass td[class="ecxflexibleContainerBox"] h3 {padding-top: 10px !important;}</style>';

$message .= '</head><body bgcolor="#EEEEEE" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0"><center style="background-color:#EEEEEE;"><table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;"><tr><td align="center" valign="top" id="bodyCell"><table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><tr><td background="http://www.bardananatural.com.br/pedido_online/images/centro.jpg" width="650" height="100" valign="top" align="center" style="color:#82b344;font-size:18px;"><img src="http://bardananatural.com.br/pedido_online/images/toponovo.jpg" alt="Bardana" width="650" height="99" /></td></tr><tr>
  <td background="http://www.bardananatural.com.br/pedido_online/images/centro.jpg" width="650" height="100" valign="top" align="center" style="color:#000000;font-size:10px;">
</p><p><a href="http://bardananatural.com.br/pesquisa-de-satisfacao/" target="new"><img src="http://www.bardananatural.com.br/pedido_online/images/bot-pesquisa.jpg" alt="Bardana" width="650" height="100" /></a>*Responda n<span style="font-weight: normal">oss</span>a pesquisa e <span style="font-weight: 600">RECEBA 5%</span> <span style="font-weight: 700">de desconto</span>  no seu proximo pedido!!<tr><td width="650" height="10"></td></tr></p><tr><td width="325" style="text-align: center; font-weight: normal; color: #82b344; font-size: 11px;"><strong>Pedido feito em ';

$message .= $data;

$message .= '</strong></td></tr></head><body bgcolor="#EEEEEE" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0"><center style="background-color:#EEEEEE;"><table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;"><tr><td align="center" valign="top" id="bodyCell"><table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><tr><td width="325" height="10" valign="top" align="center" style="color:#1361D9;font-size:14px;"><strong>Número do Pedido: 00';

$message .= $gerador;


$message .= '</head><tr><td width="650" height="10"></td></tr><body bgcolor="#EEEEEE" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0"><center style="background-color:#EEEEEE;"><table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;"><tr><td align="center" valign="top" id="bodyCell"><table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><tr><td width="650" height="14" align="center" valign="top" bgcolor="#f1f1f1" style="color:#000;font-size:10px;"><br><strong>Prazo limite para entrega:  ';

$message .= $HoraServico;

$message .= '</strong><br /><br /></td></tr><tr><td background="http://www.bardananatural.com.br/pedido_online/images/centro.jpg" width="650" valign="top" align="center"><table border="0" cellpadding="0" cellspacing="0" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;">';

$message .= '<tr><td width="295" height="20" valign="top" align="left"></td></tr><tr><td width="295" height="100" valign="top" align="left" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p><strong>Endereço: </strong>' . $endereco . '</p><p><strong>CEP: </strong>' . $cep . '</p><p><strong>Forma de Pagamento: </strong><br />' . $pagamento . '</p><p><strong>Precisa de troco?: </strong><br />' . $troco . '</p></td><td width="295" height="100" valign="top" align="left" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"><p><strong>Nome: </strong>' . $nome . '</p><p><strong>Telefone: </strong>' . $telefone . '</p><p><strong>E-mail: </strong>' . $email . '</p><p><strong>Total do seu pedido: </strong>R$ ' . $mtotal . '</p><p><strong>A Taxa de Entrega: </strong>R$ ' . $entrega . '
</p></td></tr><tr><td colspan="2" width="295" height="3" bgcolor="#82b344" style="font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"></td></tr><tr><td width="295" height="40" valign="middle" align="left" style="color:#82b344;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p><strong>Escolha a sua opção: </strong></p></td><td width="295" height="40" valign="middle" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"><p>' . $nop . $op . '</p></td></tr>';

$message .= '<tr><td colspan="2" width="293" height="3" border="1" bgcolor="#82b344" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"></td></tr><tr><td width="293" height="40" border="1" cellspacing="1" cellpadding="10" valign="top" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Pratos quentes:</strong></p>' . $quentes . '<br /><p style="color:#82b344;"><strong>Molhos escolhidos:</strong></p>' . $molhos . '<br /></td><td width="293" height="40" valign="top" cellspacing="1" cellpadding="10" bgcolor="#D7D7D7" border="1" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Saladas:</strong></p>' . $saladas . '<br /><p><strong>Observações:</strong>' . $obsfruta . '<p><strong>' . $embalagem . '</strong></td></tr></p>';

$message .= '<tr><td colspan="2" width="293" height="3" border="1" bgcolor="#82b344" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"></td></tr><tr><td width="293" height="40" border="1" cellspacing="1" cellpadding="10" bgcolor="#D7D7D7" valign="top" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Sopa do Dia:</strong></p>' . $sopas . '<br /></td><td width="293" height="40" cellspacing="1" cellpadding="10" border="1" valign="top" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Sobremesas:</strong></p>' . $sobremesas . '<br /></td></tr>';

$message .= '<tr><td colspan="2" width="293" height="3" border="1" bgcolor="#82b344" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"></td></tr><tr><td width="293" height="40" border="1" cellspacing="1" cellpadding="10" valign="top" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Sucos:</strong></p>' . $sucos . '<br /></td><td width="293" height="40" border="1" cellspacing="1" cellpadding="10" bgcolor="#D7D7D7" valign="top" align="left" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Bebidas:</strong></p>' . $bebidas . '<br /></td></tr>';

$message .= '<tr><td colspan="2" width="293" height="3" border="1" bgcolor="#82b344" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:14px;"></td></tr><tr><td colspan="2" width="293" height="40" cellspacing="1" cellpadding="10" border="1" style="color:#000000;font-family:Tahoma, Geneva, Helvetica, Arial, "Lucida Grande", sans-serif;font-size:12px;"><p style="color:#82b344;"><strong>Nosso Empório:</strong></p>' . $emporio . '<br /></td></tr>';

$message .= '<tr><td colspan="2" width="295" height="40" align="center" valign="middle" bgcolor="#82b344" style="line-height: 15px; font-size: 10px;">Obrigado pela sua preferência. Seu pedido vai chegar rapidinho!<br /><a href="www.bardananatural.com.br">www.bardananatural.com.br</a> | <strong>21. 2292-9232 | 2220-0334</strong></td></tr></table></td></tr><tr><td background="http://www.bardananatural.com.br/pedido_online/images/centro.jpg" width="650" height="50" valign="top" align="center"><img src="http://bardananatural.com.br/pedido_online/images/rodape.jpg" alt="" width="650" height="50" /></td></tr></table></td></tr></table></center></body></html>';

$to = $email;
$subject = "Seu pedido ao restaurante BARDANA - Número do Pedido: 00" .$gerador;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

//mail($to,$subject,$message,$headers);

if(mail($to,$subject,$message,$headers))
{
  echo "Seu pedido foi enviado com sucesso.<br>Você está recebendo uma cópia no endereço de e-mail que foi fornecido.<br><br>Obs.: Se você não receber a cópia do seu pedido em 10 minutos,<br>cheque a sua caixa de SPAM ou ligue para 2292-9232 | 2295-0334<br><br>";
}else{
  echo "Algo saiu errado no envio do seu pedido.<br>Por favor, ligue para 2292-9232 | 2295-0334<br><br>";
}

echo "<input type='button' id='voltar' class='botao' value=' VOLTAR ' onClick='location.replace(\"" . "http://bardananatural.com.br/" . "\");'>";
?>

The file that makes the calculation of the fees is a form.js I don’t know if I would need to look at the code of that file as well, I just need to let you know that I put.

  • Create a table with the ranges zip code and the email you want to send

  • Thank you for your attention! Friend, I am a layman, I managed to develop this form only God knows how. If you can pass me the path of stones I thank you.

1 answer

0


Make a small modification to this part of your code:

$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

Instead of the above section, you will create an array with the ceps of Copacabana, and see if the cep is from the region, if yes, send to the email there, if not, send and email as you sent before:

//coloque os ceps que deseja enviar pra copacabana 
$ceps = array('80000-000','10000-000','20000-000');
if(in_array($cep,$ceps)){
   $headers .= 'From: <[email protected]>' . "\r\n";
   $headers .= 'Cc: [email protected]' . "\r\n";
}else{
   $headers .= 'From: <[email protected]>' . "\r\n";
   $headers .= 'Cc: [email protected]' . "\r\n";
}

That should do it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.