【问题标题】:Sending HTML form by php - receiving empty email通过 php 发送 HTML 表单 - 接收空电子邮件
【发布时间】:2014-02-12 06:24:48
【问题描述】:

我有一个非常简单的 HTML 表单:

<form action="email_ok.php" method="post" enctype="text/plain"> 
Name:<br>
<input type="text" name="name" value="" size="50" required>
Email:<br>
<input type="text" name="mail" value="@" size="50" required><br>
Comment:<br>
<input type="text" name="comment" value="" size="50" required><br><br>
<input type="submit" value="SEND">
<input type="reset" value="Delete">
</form>

带有 php 文件 email_ok.php

<?php
mail('myemail@mail.com', $_POST['name'], $_POST['mail'], $_POST['comment']); ?> <p>OK</p>

但我仍然收到空邮件。怎么了?对不起,我是初学者。

非常感谢。

【问题讨论】:

标签: php html forms email send


【解决方案1】:

修改你的邮件功能如下:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

像这样:

<?php mail('myemail@mail.com', "Test subject", $_POST['comment']); ?>

您可以获取更多信息:http://in1.php.net/manual/en/function.mail.php

【讨论】:

    【解决方案2】:

    我是这样做的

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

    【讨论】:

      【解决方案3】:

      看看这个。删除 form-tag 中的 enctype,它应该可以工作。

      PHP 无法处理使用 enctype "text/plain" 发送的数据。

      method="post" enctype="text/plain" are not compatible?

      【讨论】:

        【解决方案4】:

        您正在使用必需的属性。我猜你正在使用一些 javascript 来使它们成为必需的。当您使用这种东西时,javascript 会替换您的输入标签,您可以检查您呈现的页面源。如果它更改您的 name 属性,这可能会导致问题。

        【讨论】:

          【解决方案5】:

          试试这个。

          $message = $_POST['name'].' '.$_POST['mail'].' '.$_POST['comment'];  
          mail('myemail@mail.com', 'Your subject',$message);
          

          如果您想在$_POST['mail'] 上发送电子邮件,请使用以下。

          $message = $_POST['name'].' '.$_POST['mail'].' '.$_POST['comment'];  
          mail($_POST['mail'], 'Your subject',$message);
          

          【讨论】:

            【解决方案6】:

            为你试试这个 php 代码

            <?PHP
            $email = $_POST["emailaddress"];
            $to = "you@youremail.com";
            $subject = "New Email Address for Mailing List";
            $headers = "From: $email\n";
            $message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
            
            Email Address: $email";
            $user = "$email";
            $usersubject = "Thank You";
            $userheaders = "From: you@youremailaddress.com\n";
            $usermessage = "Thank you for subscribing to our mailing list.";
            mail($to,$subject,$message,$headers);
            mail($user,$usersubject,$usermessage,$userheaders);
            ?>
            

            如果您需要完整的 html 和 php 代码,也可以告诉我。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2016-03-10
              • 1970-01-01
              • 1970-01-01
              • 2019-02-13
              • 2013-10-30
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多