0
So I created a contact form that I would need to have it formatted in the recipient email. That’s why I left HTML a little more structured and used CSS Inline for the settings, as dictated by good practices for sending HTML by email.
I stored all the code below within a variable (from which I use it later in the mail function for the message body):
<!DOCTYPE html>
<style>
table {
border-collapse: collapse;
}
td {
padding: 5px 10px;
font-family: arial;
font-size: 14px;
}
h2 {
padding: 0;
margin: 30px 0 5px 0;
font-family: arial;
font-size: 16px;
text-transform: uppercase;
}
</style>
<body>
<table width="790" align="center">
<tbody align="center" width="790">
<caption><h2 align="left">1. Dados Pessoais</h2></caption>
<tr><td colspan="3"><strong>Nome:</strong> $nome </td></tr>
<tr><td><strong>Estado Civil:</strong> $estadoCivil</td><td><strong>Resid.:</strong> $telefoneFixo</td><td><strong>Cel.:</strong> $telefoneCelular</td></tr>
<tr><td><strong>Sexo:</strong> $sexo </td><td><strong>Nascimento:</strong> $datanascimentoPessoal <td><strong>Naturalidade:</strong> $naturalidade </td>
<tr><td colspan="3"><strong>Endereço:</strong> $endereco</td></tr></tr>
<tr><td><strong>Bairro:</strong> $bairro </td><td><strong>CEP:</strong> $cep </td><td><strong>Cidade:</strong> $cidade </td></tr>
<tr><td><strong>Nome do Pai:</strong> $nomePai </td><td><strong>Nome da Mãe:</strong> $nomeMae </td></tr>
<tr><td><strong>Gru de Instrução:</strong> $grauInstrucao </td><td><strong>Completo?</strong> $grauCompleto </td><td><strong>Raça/Cor:</strong> $racaCor</td></tr>
</tbody>
</table>
<table width="790" align="center">
<tbody align="center" width="790">
<caption><h2 align="left">2. Beneficiários</h2></caption>
<tr><td><strong>Cônjuge:</strong> $conjuge </td><td><strong>Nascimento:</strong> $datanascimentoConjuge </td><td><strong>IRRF:</strong> $irrfConjuge </td></tr>
<tr><td><strong>Dependente:</strong> $dep1 </td><td><strong>Nascimento:</strong> $datanascimentoDep1 </td><td><strong>IRRF:</strong> $irrfDep1 </td></tr>
<tr><td><strong>Dependente:</strong> $dep2 </td><td><strong>Nascimento:</strong> $datanascimentoDep2 </td><td><strong>IRRF:</strong> $irrfDep2 </td></tr>
<tr><td><strong>Dependente:</strong> $dep3 </td><td><strong>Nascimento:</strong> $datanascimentoDep3 </td><td><strong>IRRF:</strong> $irrfDep3 </td></tr>
<tr><td><strong>Dependente:</strong> $dep4 </td><td><strong>Nascimento:</strong> $datanascimentoDep4 </td><td><strong>IRRF:</strong> $irrfDep3 </td></tr>
</tbody>
</table>
<table width="790" align="center">
<tbody align="center" width="790">
<caption><h2 align="left">3. Documentação</h2></caption>
<tr><td><strong>RG:</strong> $rg </td><td><strong>Orgão Exp.:</strong> $orgaoExpedidor </td><td><strong>Data de Exp.:</strong> $dataexpedicaoRG </td><td><strong>CPF:</strong> $cpf </td></tr>
<tr><td><strong>Título de Eleitor:</strong> $tituloEleitor </td><td><strong>Zona:</strong> $zonaEleitor </td><td><strong>Seção:</strong> $secaoEleitor</td></tr>
<tr><td><strong>CTPS:</strong> $ctps </td><td><strong>Série:</strong> $serieCTPS </td><td><strong>UF:</strong> $ufCTPS </td><td><strong>Data de Exp.:</strong> $dataexpedicaoCTPS </td><td><strong>PIS:</strong> $pis </td></tr>
<tr><td><strong>Carteira de Hab.:</strong> $carteiraHabilitacao </td><td><strong>Categoria:</strong> $categoriaHab </td><td><strong>Vencimento:</strong> $vencimentoHab</td><td><strong>UF:</strong> $ufHab </td><td><strong>Reservista:</strong> $reservista</td></tr>
</tbody>
</table>
<table width="790" align="center">
<tbody align="center" width="790">
<caption><h2 align="left">4. Dados Bancários</h2></caption>
<tr><td><strong>Banco:</strong> $nomeBanco </td> <td><strong>Agência:</strong> $agenciaBanco </td><td><strong>Conta:</strong> $contaBanco </td></tr>
</tbody>
</table>
<table width="790" align="center">
<tbody align="center" width="790">
<caption><h2 align="left">5. Benefícios</h2></caption>
<tr><td><strong>Vale Transporte:</strong> $valeTransporte </td><td><strong>Qtde por dia:</strong> $qtdeVT </td><td><strong>Valor da Tarifa:</strong> $valorVT </td><td><strong>Empresa:</strong> $empres </td></tr>
<tr><td colspan="4"><strong>Número Cartão Transporte/SIC:</strong> $numeroTransporte </td></tr>
<tr><td><strong>Vale Alimentação:</strong> $valeAlimentacao </td><td><strong>Vale Refeição:</strong> $valeRefeicao </td><td><strong>Valor por Dia:</strong> $valorDia </td></tr>
</tbody>
</table>
<table width="790" align="center">
<tbody align="center" width="790">
<caption><h2 align="left">6. Informações Adicionais</h2></caption>
<tr><td colspan="2"><strong>Centro de Custo:</strong> $centroCusto</td></tr>
<tr><td><strong>Já trabalhou nesta empresa:</strong> $jaTrabalhou</td> <td><strong>Contrato de Experiência:</strong> $contratoExp</td></tr>
<tr><td colspan="2"><strong>Período de Experiência:</strong> $periodoExp</td></tr>
<tr><td colspan="2"><strong>Sindicato:</strong> $sindicato</td></tr>
<tr><td colspan="2"><strong>Forma de Contratação:</strong> $formaContratacao</td></tr>
<tr><td><strong>Cargo e Funação: </strong>$cargoFuncao </td> <td><strong>Data de Início: </strong>$dataInicio</td></tr>
<tr><td><strong>Horário de Trabalho: </strong>$horarioTrabalho </td> <td><strong>Intervalo: </strong>$intervalo</td></tr>
<tr><td><strong>Sábado: </strong>$sabado </td> <td><strong>Horário: </strong>$horarioSabado </td> <td><strong>Qtde Sábados Mês: </strong>$qtdeSabado</td></tr>
<tr><td colspan="2"><strong>Salário: </strong>$salario </td></tr>
<tr><td colspan="2"><strong>Já realizou contribuição sindical este ano? </strong>$contrSindical</td></tr>
<tr><td colspan="2"><strong>Insalubridade: </strong>$insalubridade</td></tr>
<tr><td colspan="2"><strong>Crachá: </strong>$cracha</td></tr>
</tbody>
</table>
<table align="center" width="790">
<tfooter align="center" width="790">
<tr><td align="center">$data</td></tr>
</tfooter>
</table>
</body>
</html>
Set the headers correctly to indicate the message body settings:
$headers = "xxxxxxxxxxxx";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
However, when submitting the form, it is not recognizing the HTML settings.
It keeps accusing errors like (in the case of witdh="790" table):
Parse error: syntax error, unexpected '790' (T_LNUMBER)
And consequently it accuses error in all other inline settings such as width value, align, colspan, etc.
Does anyone know why this is happening?
You can not know exactly pq has no variable assignment in the question but I suspect that has a double quote before and
width="
is interpreted as the closure.– rray
Probably what @rray commented, when I have to send this email I leave the html file .html and upload the file with
file_get_contents
and give areplace
variables. Type the$data
would be like this<tr><td align="center">@data@</td></tr>
.– fernandoandrade
When will you store the HTML in the variable, as you are doing?
– caiocafardo
It was exactly that @rray ended up not paying attention to me. The error occurs because it is being interpreted the closure of the same variable. What would be the viable alternatives to this situation? I didn’t understand very well the suggestion of fernandoandrade (I’m still beginner).
– Vinicius Gabriel
@caiocabale $message = "my html";
– Vinicius Gabriel
You can use heredoc to build a template see in that reply
– rray