Php 提交带有POST和wamp更新的html表单

Php 提交带有POST和wamp更新的html表单,php,html,forms,Php,Html,Forms,试图发送测试电子邮件,下面是html表单的代码和php代码。我正在尝试使用wamp发送电子邮件。我已经更新了php.ini文件。页面一显示,下面的代码就会显示在我的消息上方 Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } } } ?> 您的

试图发送测试电子邮件,下面是html表单的代码和php代码。我正在尝试使用wamp发送电子邮件。我已经更新了php.ini文件。页面一显示,下面的代码就会显示在我的消息上方

Your message has been sent!</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    } 
    } }
    ?>

您的邮件已发送

",; }否则{ echo“出现问题,请返回并重试!

”; } } } ?>
此外,我的php代码直接位于同一文件中的表单代码之上。当我填写表格并提交时,它看起来好像提交了,但我从未收到过电子邮件

请帮帮我,我快死了

<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$from = 'From: Cruser Computers Website'; 
$to = 'mcruser@crusercomputers.com'; 
$subject = 'Hello';

$body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";

if ($_POST['submit']) {              
    if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
} }
?>

<form id='contact-form' action='' method='post' enctype="multipart/form-data">

    <div class="success">
    Contact form submitted!<br>
    <strong>We will be in touch soon.</strong>
    </div>
        <fieldset>
    <label class="name">
    <input type="text" name="name" value="Name:">
    <span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> 
    </label>
    <label class="email">
    <input type="text" name="email" value="E-mail:">
    <span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span>
    </label>
    <label class="phone">
    <input type="tel" name="phone" value="Phone:">
    <span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span>
    </label>
    <label class="message">
    <textarea name="message">Message:</textarea>
    <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span>
    </label>
    <div class="buttons-wrapper">
    <a class="button" data-type="reset">Clear</a>
    <a class="button" name="submit" data-type="Submit">Submit</a>
    </div>
    </fieldset>
</form>

联系方式已提交
我们很快就会联系。 *这不是一个有效的名称*此字段必填。 *这不是有效的电子邮件地址*此字段必填。 *这不是一个有效的电话号码*此字段必填。 信息: *信息太短了*此字段必填。 清楚的 提交
php文件必须与html文件位于不同的文件中。根据您的代码,php可能与html文件夹位于同一个文件夹中。

这就是我所能想到的,我在3种主要浏览器(chrome、mozila和IE11)中对其进行了测试

  • 提交不是一个链接,它是一个输入
  • 不要将成功消息放在表单的顶部,而是将其包含在“if(isset…)”功能下,以便仅在提交表单时才会显示
  • 仅当用户未提交其消息时,才应显示表单

    <?php
    
    //If the email is not blank
    if($_POST['email'] !== '' and isset($_POST['email'])) {
    //Email isn't blank so we can define are vars and sent the message
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $phone = $_POST['phone'];
    $from = 'From: Cruser Computers Website'; 
    $to = 'mcruser@crusercomputers.com'; 
    $subject = 'Hello';
    $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";
    if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Your message has been sent!</p>';
    }
    else{ 
        //Problem with sending mail
        echo '<p>Message could not be sent!</p>'; 
    } 
     }
     else{
    
     echo '<form id="contact-form" action="" method="post" enctype="multipart/form-data">
        <fieldset>
        <label class="name">
        <input type="text" name="name" required placeholder="Name:"> 
         </label>
         <br>
    <label class="email">
    <input type="text" name="email" required placeholder="E-mail:">
    </label>
    <br>
    <label class="phone">
    <input type="tel" name="phone"  required placeholder="Phone:">
    </label>
    <br>
    <label class="message">
    <textarea placeholder="Message" name="message"></textarea>
    </label>
    <div class="buttons-wrapper">
    <input type="reset" value="Clear">
    <input type="submit" name="submit" value="Submit"/>
    </div>
    </fieldset>
    </form>';
     }
    

    变化很大,但它最终对我有效。html应该要求现在填写每个输入。PHP通过检查电子邮件输入的值是否为空来检查是否提交了任何内容。我也做了一些样式设置

    编辑: 现在加载时不会显示任何内容

    更改:

    if($_POST['email'] !== '') {
    
    为此:

    if($_POST['email'] !== '' and isset($_POST['email'])) {
    
    PHP最终编辑代码

    <?php
    //If the email is not blank
    if($_POST['email'] !== '' and isset($_POST['email'])) {
        //Email isn't blank so we can define are vars and sent the message
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $phone = $_POST['phone'];
        $from = 'From: Cruser Computers Website'; 
        $to = 'mcruser@crusercomputers.com'; 
        $subject = 'Hello';
        $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";
    
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        }else{ 
            //Problem with sending mail
            echo '<p>Message could not be sent!</p>'; 
        } 
    }
    ?>
    
    <form id='contact-form' action='' method='post' enctype="multipart/form-data">
        <fieldset>
        <label class="name">
        <input type="text" name="name" required placeholder="Name:"> 
        </label>
        <br>
        <label class="email">
        <input type="text" name="email" required placeholder="E-mail:">
        </label>
        <br>
        <label class="phone">
        <input type="tel" name="phone"  required placeholder="Phone:">
        </label>
        <br>
        <label class="message">
        <textarea placeholder='Message' name="message"></textarea>
        </label>
        <div class="buttons-wrapper">
        <input type="reset" value="Clear">
        <input type="submit" name="submit" value="Submit"/>
        </div>
        </fieldset>
    </form>
    

    将这一行代码包含在页面的乞讨处。希望它能起作用

    <?PHP
    error_reporting(0);
    ?>
    

    在表单上方使用下面的代码

    <?php
    if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $phone = $_POST['phone'];
    $from = 'From: Cruser Computers Website'; 
    $to = 'mcruser@crusercomputers.com'; 
    $subject = 'Hello';
    
    $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";
    
    if ($_POST['submit']) {              
        if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Your message has been sent!</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    } 
    } }
    ?>
    
    
    
    我粘贴了您提供的代码,下面的代码显示在我的表单上方:您的消息已发送!

    ';}否则{echo'出现问题,请返回并重试!

    ';}}}?>谢谢你的时间。我更新了我的原始问题。谢谢你的时间。我更新了我的原始问题。谢谢你的时间。我更新了我的原始问题。谢谢你的时间。我更新了我的原始问题。谢谢你在这方面的努力,但我仍然会在页面显示时看到表格上方的回音线。这是什么它会显示?脚本对您有效吗?您的邮件已发送!;}否则{//发送邮件回显时出现问题“无法发送邮件!”;}}?>电子邮件将不会发送。我认为这与通过wamp服务器进行smtp身份验证有关。我正在尝试将网站托管在GoDaddy上,并使用formmail应用程序发送电子邮件。您使用的浏览器是什么,因为它对我有效!