联系表格工作,发送电子邮件,信息丢失

时间:2017-06-03 19:12:35

标签: php html forms

我从下面创建了此联系表单。一切都很好,直到我试图在电子邮件表单中添加另一个部分到“正文”。第一条消息可以附加到正文,但我不能说HTML表单中的另一部分可以正常工作。

这个表格有什么问题?谢谢你的帮助。

<form method="post" action="emailform.php">             
    <fieldset>
        <ul>
        <li>
        <label for="name">Your Name:</label>
        <input type="text" name="name" id="name"class="large" required="required" placeholder="Enter your name"/></li><!--Basically gave a name here-->

        <li>   
        <label for="idlabel">Your Email:</label>
        <input type="email" name="email"  placeholder="Enter your email"/></li><!--Basically gave a name here-->

         <label for="message2"> <textarea name="message2" maxlength="800" rows="6"
        cols="23"></textarea></li></ul>




        <li><label for="message">Enter Your Message Below</label> 
            <textarea name="message" maxlength="800" rows="6"
        cols="23"></textarea></li></ul><!--Basically gave a name here and removed label as name-->

        <input type="submit" value="Submit"/>
    </fieldset>    
</form>



<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Emailing Form Data</title>
    <style type="text/css">

    body {
        font-size: 100%;
        font-family: Arial, sans-serif;
    }
    </style>
</head>
<body>

<?php

if (empty($_POST)) {
    print "<p>No data was submitted.</p>";
    print "</body></html>";
    exit();
}

/* Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman! */
function clear_user_input($value) {
    if (get_magic_quotes_gpc()) $value=stripslashes($value);
    $value= str_replace( "\n", '', trim($value));
    $value= str_replace( "\r", '', $value);
    return $value;
}


/* Create body of email message by cleaning each field and then appending each name and value to it. */

$body ="Here is the data that was submitted:\n";
//Fetching the form fields here
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$message2 = $_REQUEST['message2'];
$message = $_REQUEST['message'];



/* Removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers */
$email   = clear_user_input($email);
$name    = clear_user_input($name);

$body   .= clear_user_input($message); + clear_user_input($message2); //Appending the message to the body of the email

/* Create header that puts email in From box along with name in parentheses and sends Bcc to alternate address. Change yourmail@yourdomain.com to the Bcc email address you want to include. */
$from='From: '. $email . "(" . $name . ")" . "\r\n" . 'Bcc: yourmail@yourdomain.com' . "\r\n";

// Creates intelligible subject line that also shows me where it came from
$subject = 'New User Sign Up!';

/* Sends mail to the address below with the form data submitted above. Replace yourmail@yourdomain.com with the email address to which you want the data sent. */
mail ('yourmail@yourdomain.com', $subject, $body, $from);
?>

<p>Thank you.</p>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

更改

$body .= clear_user_input($message); + clear_user_input($message2);

$body .= clear_user_input($message).clear_user_input($message2);

此外,您可能希望对所有传递的值(有效电子邮件,空值等等)的有效性添加大量检查,因为您将收到大量空的或垃圾邮件。