php - Why is this e-mail form using validation resulting in an error?
问题描述
error i'm getting is "Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing"
else
{
$emailTo ="me@domain.com";
$subject =$_POST['subject'];
$content =$_POST['content'];
$headers = "From : ".$_POST['email'];
if (mail( $emailTo, $subject , $content, $headers))
{
$successfulMessage ='<div class="alert alert-success" role="alert">Your message is sent,We\'ll get back to you soon </div>' ;
}
else
{
$error = '<div class="alert alert-danger" role="alert"><p><strong>Your message coudn\'t be sent</strong></p> </div>' ;
}
}
解决方案
Your From header is incorrectly formatted. Change
$headers = "From : " . $_POST['email'];
to
$headers = "From: " . $_POST['email'];
But I'd suggest something more extensive like in the answer found here: [PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header missing
And just in case you're not running Unix and encounter the smtp error after this: Failed to connect to mailserver at "localhost" port 25
推荐阅读
- java - 我们可以从 linux Shell Script 或 Crontab 调用 Java Method 吗?
- java - Spring MVC 测试缺少来自 MockMvc 示例的导入
- splunk-query - 在 splunk 中搜索唯一 IP
- docker - Kubernetes:将 pod STDOUT、STDERR 和 pod 终止日志重定向到 PVC 文件
- java - 动态(以编程方式)创建视图时,视图在卡片视图中重叠
- spring-boot - 无法从 spring 控制器打印 JSP,但结果是在控制台中打印
- java - 上下文:组件扫描在 junit 中不起作用
- php - 如何使用codeigniter同时创建多个excel文件
- javascript - 创建矩形后如何动态附加文本
- sql - 计算一列中的行但在不同的日期