将主题添加到SENDMAIL.PHP文件

时间:2016-01-11 02:24:33

标签: php forms sendmail contact-form

我有以下代码来运行我的联系表单。该代码效果很好,但我很乐意将强制主题添加到我收到的电子邮件中,因为它目前显示为“(无主题)”。有什么提示吗?

<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email']) && isset($_POST['project_name']) && isset($_POST['description'])  && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
    // detect & prevent header injections
    $test = "/(content-type|bcc:|cc:|to:)/i";
    foreach ( $_POST as $key => $val ) {
        if ( preg_match( $test, $val ) ) {
        exit;
    }
}

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$project_name = $_POST['project_name'];
$description = $_POST['description'];

$message = "
First Name: $first_name \n
Last Name: $last_name\n
Project Name: $project_name\n
Description: $description
";

mail( "email@email.com", $_POST['date'], $message, "From:" . $_POST['email'] );
  //            ^
  //  Replace with your email
}
?>

2 个答案:

答案 0 :(得分:2)

mail函数的第二个参数是... Update the database ... [self showProgressNotification]; // Reload the content showing a notification dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ // Reload the content [self generateContent]; dispatch_async(dispatch_get_main_queue(), ^{ [self hideProgressNotification]; }); }); 参数。 可能是您$subject的值未定义,导致收件人看到(没有主题)&#39;

尝试将邮件功能更改为:

$_POST['date']

在此处阅读更多内容:http://php.net/manual/en/function.mail.php

  

用法 bool邮件(字符串$ to,字符串$ subject,字符串$ message [,字符串$ additional_headers [,字符串$ additional_parameters]])

答案 1 :(得分:1)

require属性添加到生成的联系表单(对于主题输入字段)html标记。它会强制填写主题字段,然后才能提交。

Read a little more about the "required" attribute