0

我正在使用以下内容让联系页面向我发送包含访问者数据的电子邮件。

            <form method="post" action="submit.php">
            <label for="Name">Name</label>
            <input type="text" name="Name" id="Name" />

            <label for="Email">eMail</label>
            <input type="text" name="Email" id="Email" />



            <input type="submit" name="submit" value="Send" class="submit-button" />
            </form>

和PHP:

    <?php

    $EmailFrom = "Me";
    $EmailTo = "me@me.com";
    $Subject = "Test";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 

    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "eMail: ";
    $Body .= $Email;
    $Body .= "\n";

    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>

尝试时,我只得到 PHP 文件准备的电子邮件正文,但没有访问者插入的信息,如下所示:

姓名: 电子邮件:

4

2 回答 2

0

尝试为电子邮件设置标题信息:

$header  = 'MIME-Version: 1.0'."\r\n";
$header .= 'Content-type: text/plain; charset=iso-8859-1'."\r\n";
$header .= 'From: '.$EmailFrom."\r\n";

$success = mail($EmailTo, $Subject, $Body, $header);
于 2012-07-04T08:24:36.027 回答
0

最后我只是稍微简化了一点..这似乎是一个“区分大小写”的问题,它阻止了表单与 php 文件进行通信。

所以这就是最终奏效的方法:

            <form method="post" action="submit.php">
            <label for="Name">Name</label>
            <input type="text" name="Name" id="name" />

            <label for="Email">eMail</label>
            <input type="text" name="Email" id="email" />

            <label for="Message">Message</label>
            <textarea name="Message" rows="10" id="message"></textarea>

            <input type="submit" name="submit" value="Send" class="submit" id="submit"/>
            </form>

和PHP:

        <?php


    $EmailFrom = "Test";
    $EmailTo = "test@test.com";
    $Subject = "Testing";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $Message = Trim(stripslashes($_POST['Message'])); 

    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "eMail: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>
于 2012-07-04T12:59:14.240 回答