电子邮件发送功能不发送数据

时间:2015-05-10 05:04:29

标签: php email post

当我发送任何邮件时,这将只返回名称:from:message:subject:,但所有这些字段都是空白的..

<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to         = 'me@example.com';

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;

1 个答案:

答案 0 :(得分:0)

在不了解您的环境的情况下,mail函数将headers参数接受为字符串,而不是数组。

mail($to, $subject, $message, implode("\r\n", $headers));

http://php.net/manual/en/function.mail.php