PHP邮件导致错误:“header missing” [英] PHP Mail results in error: "header missing"
问题描述
我一直在使用php邮件表单一段时间,现在它不能在一个新的网站上工作。
I've been using a php mail form for some time now and now it's not working on a new website.
以下错误结果:
PHP警告:mail()[function.mail]:sendmail_from不在php.ini中设置或自定义发件人:标题在E:\home\ -mypagefoldername- \Web\form.php第16行缺少
PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\home\ -mypagefoldername- \Web\form.php on line 16
这是form.php文件中的php代码:
This is the php code in the form.php file:
<?
$mensagem = "Nome: ".$_POST['nome']." \n";
//email que o usuário preencheu
$mensagem .= "Email: ".$_POST['email']." \n";
$mensagem .= "Assunto: ".$_POST['assunto']." \n";
$mensagem .= "Telefone: ".$_POST['fone']." \n";
$mensagem .= "Endereço: ". $_POST['mensagem'];
$headers = "";
//email do seu domínio hospedado
$emailsender = "email@mydomain.com";
//email de quem vai receber
$emaildestinatario = "email@mydomain.com";
$assunto = "Mensagem do Parceiro Pipa";
// Envio dos dados do Formulário para seu e-mail:
if(!mail($emaildestinatario, $assunto, $mensagem, $headers ,"-r".$emailsender))
{
// Se for Postfix - hospedagem linux
$headers .= "Return-Path: " . $emailsender . $quebra_linha;
}
echo '
<script type="text/JavaScript">
alert("Email sent! Thank you!");
location.href="index.html"
</script>
';
?>
对不起葡萄牙语。
表单页面是一个带有以下表单代码的简单html页面:
The form page is a simple html page with the following form code:
<form method="post" action="form.php">
<label>Nome</label>
<input name="nome" placeholder="Nome completo.">
<label>Telefone</label>
<input name="fone" placeholder="Número de telefone com DDD.">
<label>Assunto</label>
<input name="assunto" placeholder="Qual o motivo do seu contato?">
<label>Mensagem</label>
<textarea name="mensagem" placeholder="Escreva aqui sua mensagem."></textarea>
<label>Email</label>
<input name="email" type="email" placeholder="Email para contato.">
<input id="submit" name="submit" type="submit" value="Enviar">
</form>
有人可以帮我吗? = /
Could somebody please help me? =/
感谢您的耐心等待。
推荐答案
说,你可能在 $ headers
变量中缺少 From:
声明!
As it says, you're probably missing the From:
declaration in your $headers
variable!
<?php
$From = "YourEmailAddress@example.com";
$headers .= "From: Your Name <". $From .">\n";
?>
到$ $ header
字符串。虽然以后参考,你可能想看看PHPMailer类,一个非常好的&有效处理PHP 邮件
的安全类。
To the near the top of your $headers
string. Although for future reference, you might want to take a look at PHPMailer Class, a very good & secure class that handles the PHP mail
efficiently.
这篇关于PHP邮件导致错误:“header missing”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!