3
Guys, I made a Landing page on the company page and it sends the information that people fill out to my email using Phpmailer. Most of the e-mails are coming straight through, with all the necessary information. However, some emails are coming empty, as if the variables were empty; as in the image below:
The code that sends the email is on the "Thank you" page, which recovers the data via post:
$identificador = $_POST['identificador'];
$nome = $_POST['nome'];
$email = $_POST['email'];
$empresa = $_POST['company'];
$cargo = $_POST['cargo'];
$nfuncionarios = $_POST['func'];
$tipopessoa = $_POST['pessoa'];
$dificuldade = $_POST['dificuldade'];
//... recuperar os dados do formulario via post
require 'mailer/PHPMailerAutoload.php';
$Mailer = new PHPMailer();
// define que será usado SMTP
$Mailer->IsSMTP();
// envia email HTML
$Mailer->isHTML(true);
// codificação UTF-8
$Mailer->Charset = 'UTF-8';
// Configurações do SMTP
$Mailer->SMTPAuth = true;
$Mailer->Host = 'br296.hostgator.com.br';
$Mailer->Port = 25;
$Mailer->Username = '[email protected]';
$Mailer->Password = 'minha senha está aqui';
// E-Mail do remetente
// nesse caso email-do-cliente@)
$Mailer->From = '[email protected]';
// Nome do remetente-cliente
$Mailer->FromName = 'Kamers Marketing';
// assunto da mensagem
$Mailer->Subject = 'Ebook Marketing Digital: Passo a Passo';
// corpo da mensagem
$Mailer->Body = '<p><b>'.$nome.', baixou seu ebook "'.$identificador.'"</b>.</p> <p>E-mail para contato: '.$email.'<br><br>Empresa: '.$empresa.'<br><br>Cargo: '.$cargo.'<br><br>Número de Funcionários: '.$nfuncionarios.'<br><br>Tipo de pessoa: '.$tipopessoa.'<br><br>Principal Dificuldade: '.$dificuldade.'</p>';
// adiciona destinatário /*para onde a mensagem será enviada*/
$Mailer->AddAddress('[email protected]');
$Mailer->AddAddress('[email protected]');
// verifica se enviou corretamente
if ($Mailer->Send())
{
}
else
{
('Location: marketing-digital-passo-a-passo');
}
I’ve run several tests on the form, but his validation is right, he doesn’t pass empty fields. I imagine this would happen if someone accessed the "Thank you" page directly through the url without filling in the data before, but it’s strange that it happens so many times...
Well, maybe it’s the validation I made with Pattern in html:
<!--no action do form vai para pagina de agradecimento-->
<form id="conversion-form" action="obrigado" method="POST" onsubmit="imgloader()">
<input type="hidden" name="identificador" value="Marketing Digital: Passo a Passo">
<div class="field">
<label for="name">Nome*</label>
<input type="text" required name="nome" id="name" pattern="^([^*]{3,20})+\ ([^*]{3,20})$" title="Seu Nome Completo, por favor" value="" class="form-control required">
</div>
<div class="field">
<label for="email">Email*</label>
<input type="email" required name="email" id="email" title="Insira um E-mail Válido" pattern="^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" value="" class="form-control required">
</div>
<div class="field">
<label for="company">Empresa*</label>
<input type="text" required name="company" pattern="^[^*]{2,20}" id="company" value="" class="form-control required">
</div>
<div class="field">
<label for="custom_fields_8346">Cargo*</label>
<select required name="cargo" id="custom_fields_8346" class="form-control required">
<option value="" disabled selected>Selecione</option>
<option value="CEO / Sócio">CEO / Sócio</option>
<option value="Diretor">Diretor</option>
<option value="Gerente/Coordenador de marketing">Gerente/Coordenador de marketing</option>
<option value="Gerente/Coordenador de vendas">Gerente/Coordenador de vendas</option>
<option value="Analista de marketing">Analista de marketing</option>
<option value="Outros cargos">Outros cargos</option>
</select>
</div>
<div class="field">
<label for="custom_fields_8341">Número de funcionários*</label>
<select required name="func" id="custom_fields_8341" class="form-control required">
<option value="" disabled selected>Selecione</option>
<option value="1 - 5">1 - 5</option>
<option value="6 - 10">6 - 10</option>
<option value="11 - 25">11 - 25</option>
<option value="26 - 50">26 - 50</option>
<option value="51 - 200">51 - 200</option>
<option value="201 - 1.000">201 - 1.000</option>
<option value="mais de 1.000">mais de 1.000</option>
</select>
</div>
<div class="field">
<label for="custom_fields_17882">Como você se define*</label>
<select required name="pessoa" id="custom_fields_17882" class="form-control required">
<option value="" disabled selected>Selecione</option>
<option value="Estudante buscando conhecimento">Estudante buscando conhecimento</option>
<option value="Funcionário procurando informações">Funcionário procurando informações</option>
<option value="Empresa procurando soluções">Empresa procurando soluções</option>
</select>
</div>
<div class="field">
<label for="custom_fields_17930">Principal Dificuldade*</label>
<select name="dificuldade" id="custom_fields_17930" class="form-control required" required>
<option value="" disabled selected>Selecione</option>
<option value="Gerar mais leads">Gerar mais leads</option>
<option value="Leads mais qualificados">Leads mais qualificados</option>
<option value="Aumentar as vendas">Aumentar as vendas</option>
<option value="Aumentar visitas">Aumentar visitas</option>
<option value="Estou totalmente perdido">Estou totalmente perdido</option>
</select>
</div>
<div class="field">
<label><span id="math_expression">3 + 7 = ?</span></label>
<input required type="text" name="captcha" class="math">
</div>
<!--fim do formulario*****************-->
<div class="actions">
<input type="submit" class="call_button" value="RECEBER MATERIAL">
</form>
You know if it’s some mistake I didn’t see?
Do not care too much about it, negative costs little score. The validation part would be good by also, goes that the problem is just there. The shipping part seems normal in principle. About your Location header, regardless of the issue, see if it’s in the right place, to avoid repeated submissions with F5.
– Bacco
It would be very important to validate in PHP as well. Not all browsers require client-side validation, and server-side validation is always required. The client side serves more as convenience, for those who are using not forget a field, for example. Look at this question, to get an idea of the problem: Using client validation is sufficient?
– Bacco
Man, I thought this validation with patern would be enough. Thank you very much, I’ll do a validation with php too.
– Maira
Anyway, let’s see if there are any interesting answers here. But do a search, there are some examples here by the site.
– Bacco
you have to validate the form requirement, otherwise the guy just clicks on the send button and sends everything empty.
– Ivan Ferrer
If you put on the "Thank you" page a validation that the $_POST['name'] variable is filled, it will already delete all blank emails sent due to someone trying to access the page directly.
– Rafael Mena Barreto
@Maira basically what you need to think are two things: to validate, just a sequence of ifs between $post and require, to validate the fields, and in case of not validating, has an important detail: present the form again with the data that the person has already typed. For this, it would be the case to add in the values of the form something like
value="<?php echo htmlentities( $nome ) ?>"
etc. In these cases it is much easier to stay on the page that processes the data. MVC purists hate it, but normal programmer does what is objective, fashion independent (after all, it’s PHP, Oras).– Bacco