似乎无法获得PHP表单来显示

时间:2022-09-22 15:12:08

I am working on my version 2 of my portfolio site, I had a working mailer I created with a guide about a year ago, transferred it, and can't get my page to display now.

我在我的投资组合网站的第2版上工作,我有一个工作邮件,我在大约一年前创建了一个指南,转移了它,现在无法显示我的页面。

Here is the code I am using:

这是我正在使用的代码:

<?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
       {
                //send email
            $name = $_REQUEST['name'] ;
            $email = $_REQUEST['email'] ;
            $subject = $_REQUEST["My_Portfolio_Website"] ;
            $message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;

            echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";

        }else{
        //if "email" is not filled out, display the form
            echo <form method="post" action="contact.php" class="connect">
          <div>
            <input id="name" name="name" type="text" required>
            <label for="name">Your Name</label>
          </div>
          <div>
            <input id="email" name="email" type="text" required>
            <label for="email">Your Email</label>
          </div>
          <div>
            <textarea id="message" name="message" required></textarea>
            <label for="message">Your Message</label>
          </div>
          <div class="metro">
            <div class="metro-button" type="submit">Click me</div> 
            </div>
        </form>

        } 
?>

I ran it through a PHP syntax checker and it did not pull anything out, does anyone have any ideas?

我通过PHP语法检查器运行它并没有提取任何东西,有没有人有任何想法?

For reference: Here is the original code I used on Version 1. I formatted it so it would display the email a little more cleaner, which probably royally screwed it up.

供参考:这是我在版本1上使用的原始代码。我对其进行了格式化,因此它会使电子邮件显示得更清晰一点,这可能会让它变得更加清晰。

<?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
       {
                //send email
            $name = $_REQUEST['name'] ;
            $email = $_REQUEST['email'] ;
            $subject = $_REQUEST["My Portfolio Website"] ;
            $message = $_REQUEST['message'].", Name: ".$name.", ".$phone.", Email: ".$email;
            mail("TylerJStelmach@gmail.com", $subject, $message, "From:" . $email);
            echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
        }else{
        //if "email" is not filled out, display the form
            echo "<form method='post' action='index.php'>

                <input type='text' input name='name' id='name' class='contacttext' placeholder=' Your Name' required>
                <input type='text' input name='email' id='email' class='contacttext' placeholder=' Your Email Address' required>
                <textarea input type='text' name='message' id='message' class='contacttext' placeholder=' Your Message' cols='55' rows='5' required></textarea>

                <input type='submit' id='submit' class='submitcontacttext' value='Send Message'>
                </form>";
        }
?>  

3 个解决方案

#1


There are some syntax errors.

有一些语法错误。

Also, your snipplet does not contain code to send mail.

此外,您的snipplet不包含发送邮件的代码。

Corrected code is as following:

更正后的代码如下:

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
     {
                        //send email
                $name = $_REQUEST['name'] ;
                $email = $_REQUEST['email'] ;
                $subject = $_REQUEST["My_Portfolio_Website"] ;
                $message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;

                echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";

        }else{
        //if "email" is not filled out, display the form
                echo '<form method="post" action="contact.php" class="connect">
            <div>
                <input id="name" name="name" type="text" required>
                <label for="name">Your Name</label>
            </div>
            <div>
                <input id="email" name="email" type="text" required>
                <label for="email">Your Email</label>
            </div>
            <div>
                <textarea id="message" name="message" required></textarea>
                <label for="message">Your Message</label>
            </div>
            <div class="metro">
                <div class="metro-button" type="submit">Click me</div> 
                </div>
        </form>';
        } 
?>

#2


as all are saying where is the line to send mail but as i have seen your site there is no sign of any code.

因为所有人都在说发送邮件的行在哪里但是因为我看到你的网站没有任何代码的迹象。

as i am just guessing, even if the if is false, the else should run as it is running in my localhost.

因为我只是在猜测,即使if为false,else也应该在我的localhost中运行时运行。

the problem must be something with your sever. put a error_reporting(E_ALL); on top it will show errors if it there.

问题必须与您的服务器有关。放一个error_reporting(E_ALL);如果在那里,它将显示错误。

else try writing in a new file.

否则尝试写入新文件。

<?php
    error_reporting(E_ALL);
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
       {
                //send email
            $name = $_REQUEST['name'] ;
            $email = $_REQUEST['email'] ;
            $subject = $_REQUEST["My_Portfolio_Website"] ;
            $message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;

            echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";

        }else{
            ?>

            <form method="post" action="contact.php" class="connect">
          <div>
            <input id="name" name="name" type="text" required>
            <label for="name">Your Name</label>
          </div>
          <div>
            <input id="email" name="email" type="text" required>
            <label for="email">Your Email</label>
          </div>
          <div>
            <textarea id="message" name="message" required></textarea>
            <label for="message">Your Message</label>
          </div>
          <div class="metro">
            <div class="metro-button" type="submit">Click me</div> 
            </div>
        </form>
<?php
        } 
?>

#3


I was able to figure this out by re-writing the original code I had based on the guide I used about a year ago, I came up with this for the answer which indeed works.

我能够通过重写基于我大约一年前使用的指南的原始代码来解决这个问题,我想出了答案,确实有效。

For all of the handling of where the information goes and how it was formated I included this chunk of php before I declared the doctype.

对于所有处理信息的位置以及它是如何格式化的,我在声明doctype之前包含了这一块php。

<?php

if($_POST["submit"]) {
    $recipient="myemail@email.com";
    $subject="Client Mail";
    $name=$_POST["name"];
    $email=$_POST["email"];
    $email_from = $_POST['email'];
    $message=$_POST["message"];


    $mailBody="Name: $name\nEmail: $email\n\nMessage: $message";

    mail($recipient, $subject, $mailBody, "From: $sender <$email>");

    $thankYou="<p class='thank-you'>Thank you! Your message has been sent.</p>";
}

?>

From here, I figured out that the reason it wasn't submitting to it's own page was because my submit button was neither a button or input. I had it set as a div so with some tweaks here and there I rewrote the lower half to include an input as the submit. Which left me with this:

从这里,我发现它没有提交到它自己的页面的原因是因为我的提交按钮既不是按钮也不是输入。我把它设置为div所以在这里和那里进行一些调整我重写了下半部分以包含输入作为提交。这让我想到了这个:

<?=$thankYou ?>

I included a small amount of text to display ( the $thankYou ) when you submit to the page and it reloads.

当您提交到页面并重新加载时,我包含了少量要显示的文本($ thankYou)。

 <form method="post" action="contact.php" class="connect">
          <div>
            <input id="name" name="name" type="text" required>
            <label for="name">Your Name</label>
          </div>
          <div>
            <input id="email" name="email" type="text" required>
            <label for="email">Your Email</label>
          </div>
          <div>
            <textarea id="message" name="message" required></textarea>
            <label for="message">Your Message</label>
          </div>
          <div class="metro">
            <input type="submit" name="submit" class="metro-button submit-me">
            </div>
        </form>

So now when submitted, the email comes in with: The 'from' being set by $email The 'subject' being set by $subject and the message ($message) being formatted in this manner:

因此,现在提交时,电子邮件附带:'from'由$ email设置'subject'由$ subject设置,消息($ message)以这种方式格式化:

Name: John Doe
Email: JDoe@fake.com

Message: This is John Doe's message.

My apologies for the terrible question phrasing before hand, it was late at night and I was getting frustrated and losing my place, got a good nights rest and was able to solve it.

我为那可怕的问题表示道歉,那是在深夜,我很沮丧,失去了我的位置,得到了一个良好的夜晚休息,并能够解决它。

Here is the live version, I encourage you to test it, it works for me perfectly, hopefully this snippet can help someone else in the future!

这是现场版,我鼓励你测试一下,它对我很有用,希望这个片段可以在将来帮助别人!

#1


There are some syntax errors.

有一些语法错误。

Also, your snipplet does not contain code to send mail.

此外,您的snipplet不包含发送邮件的代码。

Corrected code is as following:

更正后的代码如下:

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
     {
                        //send email
                $name = $_REQUEST['name'] ;
                $email = $_REQUEST['email'] ;
                $subject = $_REQUEST["My_Portfolio_Website"] ;
                $message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;

                echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";

        }else{
        //if "email" is not filled out, display the form
                echo '<form method="post" action="contact.php" class="connect">
            <div>
                <input id="name" name="name" type="text" required>
                <label for="name">Your Name</label>
            </div>
            <div>
                <input id="email" name="email" type="text" required>
                <label for="email">Your Email</label>
            </div>
            <div>
                <textarea id="message" name="message" required></textarea>
                <label for="message">Your Message</label>
            </div>
            <div class="metro">
                <div class="metro-button" type="submit">Click me</div> 
                </div>
        </form>';
        } 
?>

#2


as all are saying where is the line to send mail but as i have seen your site there is no sign of any code.

因为所有人都在说发送邮件的行在哪里但是因为我看到你的网站没有任何代码的迹象。

as i am just guessing, even if the if is false, the else should run as it is running in my localhost.

因为我只是在猜测,即使if为false,else也应该在我的localhost中运行时运行。

the problem must be something with your sever. put a error_reporting(E_ALL); on top it will show errors if it there.

问题必须与您的服务器有关。放一个error_reporting(E_ALL);如果在那里,它将显示错误。

else try writing in a new file.

否则尝试写入新文件。

<?php
    error_reporting(E_ALL);
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
       {
                //send email
            $name = $_REQUEST['name'] ;
            $email = $_REQUEST['email'] ;
            $subject = $_REQUEST["My_Portfolio_Website"] ;
            $message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;

            echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";

        }else{
            ?>

            <form method="post" action="contact.php" class="connect">
          <div>
            <input id="name" name="name" type="text" required>
            <label for="name">Your Name</label>
          </div>
          <div>
            <input id="email" name="email" type="text" required>
            <label for="email">Your Email</label>
          </div>
          <div>
            <textarea id="message" name="message" required></textarea>
            <label for="message">Your Message</label>
          </div>
          <div class="metro">
            <div class="metro-button" type="submit">Click me</div> 
            </div>
        </form>
<?php
        } 
?>

#3


I was able to figure this out by re-writing the original code I had based on the guide I used about a year ago, I came up with this for the answer which indeed works.

我能够通过重写基于我大约一年前使用的指南的原始代码来解决这个问题,我想出了答案,确实有效。

For all of the handling of where the information goes and how it was formated I included this chunk of php before I declared the doctype.

对于所有处理信息的位置以及它是如何格式化的,我在声明doctype之前包含了这一块php。

<?php

if($_POST["submit"]) {
    $recipient="myemail@email.com";
    $subject="Client Mail";
    $name=$_POST["name"];
    $email=$_POST["email"];
    $email_from = $_POST['email'];
    $message=$_POST["message"];


    $mailBody="Name: $name\nEmail: $email\n\nMessage: $message";

    mail($recipient, $subject, $mailBody, "From: $sender <$email>");

    $thankYou="<p class='thank-you'>Thank you! Your message has been sent.</p>";
}

?>

From here, I figured out that the reason it wasn't submitting to it's own page was because my submit button was neither a button or input. I had it set as a div so with some tweaks here and there I rewrote the lower half to include an input as the submit. Which left me with this:

从这里,我发现它没有提交到它自己的页面的原因是因为我的提交按钮既不是按钮也不是输入。我把它设置为div所以在这里和那里进行一些调整我重写了下半部分以包含输入作为提交。这让我想到了这个:

<?=$thankYou ?>

I included a small amount of text to display ( the $thankYou ) when you submit to the page and it reloads.

当您提交到页面并重新加载时,我包含了少量要显示的文本($ thankYou)。

 <form method="post" action="contact.php" class="connect">
          <div>
            <input id="name" name="name" type="text" required>
            <label for="name">Your Name</label>
          </div>
          <div>
            <input id="email" name="email" type="text" required>
            <label for="email">Your Email</label>
          </div>
          <div>
            <textarea id="message" name="message" required></textarea>
            <label for="message">Your Message</label>
          </div>
          <div class="metro">
            <input type="submit" name="submit" class="metro-button submit-me">
            </div>
        </form>

So now when submitted, the email comes in with: The 'from' being set by $email The 'subject' being set by $subject and the message ($message) being formatted in this manner:

因此,现在提交时,电子邮件附带:'from'由$ email设置'subject'由$ subject设置,消息($ message)以这种方式格式化:

Name: John Doe
Email: JDoe@fake.com

Message: This is John Doe's message.

My apologies for the terrible question phrasing before hand, it was late at night and I was getting frustrated and losing my place, got a good nights rest and was able to solve it.

我为那可怕的问题表示道歉,那是在深夜,我很沮丧,失去了我的位置,得到了一个良好的夜晚休息,并能够解决它。

Here is the live version, I encourage you to test it, it works for me perfectly, hopefully this snippet can help someone else in the future!

这是现场版,我鼓励你测试一下,它对我很有用,希望这个片段可以在将来帮助别人!