【发布时间】:2019-02-17 17:39:41
【问题描述】:
我正在尝试发送一封带有联系表格的电子邮件,但它没有显示数据。 我在这里尝试了一些答案,但无法正常工作。
我的代码:
<form class="form form-container method="post" action="assets/send_form_email.php">
<div class="left">
<input name="f_name" type="text" id="f_name" placeholder="Nome*" required />
<input name="f_email" type="email" id="f_email" placeholder="Email*" required />
<input name="f_phone" type="text" id="f_phone" required="required" maxlength="15" placeholder="Telefone*" />
<textarea name="f_msg" id="f_msg" placeholder="Mensagem" rows="6"></textarea>
</div>
<div class="right">
<input name="f_cnpj" type="text" id="f_cnpj" placeholder="CNPJ" style="font-weight: 700;" required />
<input name="f_sector" type="text" id="f_sector" placeholder="Setor da empresa" style="font-weight: 700;" required />
<input name="f_faturamento" type="text" id="f_faturamento" placeholder="Faturamento médio" style="font-weight: 700;" required />
<input name="f_valorMedio" type="text" id="f_valorMedio" placeholder="Valor médio de duplicatas" style="font-weight: 700;" required />
<button type="submit" class="botaoContato">Enviar</button>
</div>
</form>
这里是 PHP:
<?php
$nome = $_POST['f_name'];
$email = $_POST['f_email'];
$telefone = $_POST['f_phone'];
$cnpj = $_POST['f_cnpj'];
$setor = $_POST["f_sector"];
$faturamento = $_POST['f_faturamento'];
$valorMedio = $_POST['f_valorMedio'];
$msg = $_POST["f_msg"];
$mensagem = "Nome: '.$nome.' <br>
Email: '$email.' <br>
Telefone: '.$telefone.' <br><br>
CNPJ: '.$cnpj.' <br>
Setor: '.$setor.' <br>
Faturamento: '.$faturamento.' <br>
Valor Medio: '.$valorMedio.' <br>
Mensagem: '.$msg.' <br>";
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPDebug = 2;
$mail->IsSMTP();
$mail->Host = "smtp.****.com.br";
$mail->SMTPAuth = true;
$mail->Username = 'contato@****.com.br';
$mail->Password = '********';
$mail->From = "contato@*****.com.br";
$mail->Sender = "contato@****.com.br";
$mail->FromName = "****";
$mail->AddAddress('contato@*****.com.br');
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = "Contato Site ";
$mail->Body = $mensagem;
$mail->AltBody = $mensagem;
$enviado = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
if ($enviado) {
echo "E-mail enviado com sucesso!";
} else {
echo "Não foi possível enviar o e-mail.
";
echo "Informações do erro:
" . $mail->ErrorInfo;
}
我尝试删除变量并将其直接添加到 $mail->Body 但它不起作用。我不太了解 PHP,所以我依赖这里的帖子或一些教程,但我找不到错误。 :(
【问题讨论】: