dotwc62080 2013-11-25 19:21
浏览 17

为什么这不起作用?

I've this little script to send email! But it's not working... Firstly it says that my variables are not defined and then, they confirm me that the message has been sent, but it doensn't happen!

Name:      
        <form action="contactus.php" method="POST">
            <input type="text" size="32" value="" name="name">
        </form> <br><br>
    E-Mail: &nbsp;&nbsp;&nbsp;&nbsp;
        <form action="contactus.php" method="POST">
            <input type="text" size="32" value="" name="header">
        </form> <br><br>
    Subject: &nbsp;&nbsp;
        <form action="contactus.php" method="POST">
            <input type="text" size="32" value="" name="subject">
        </form> <br><br>
    Message: <br>
    <form action="contactus.php" method="POST">
        <textarea rows="10" cols="40" name="message" value=""></textarea>
    </form>
    <br><br>

    <form action="contactus.php" method="POST">
        <input type="submit" value="Submit" name="submit">
    </form>


    <?php

    // php script to send emails 

    $to = 'some@email.com';

    if (isset ($_POST['message'])) {
        $message = "$name" . "<br><br>" . $_POST['message'];
    }


    if (isset ($_POST['header'])) {
        $header = "From:" . $_POST['header'];
    }


    if (isset ($_POST['subject'])) {
        $subject = ($_POST['subject']);
    }

    if (isset ($_POST['name'])) {
        $name = ($_POST['name']);
    } 




    if (isset($_POST['submit'])){
    mail($to, $subject, $message, $header);
    echo "Your message has been sent!";
    }



    //end of the php script

    ?>

If some of you can help me would be great!

Thank you.

  • 写回答

3条回答 默认 最新

  • dongxia1390 2013-11-25 19:28
    关注

    You can't use all those different form elements. You are using 5 separate forms and the only one that is being submitted is the one with the submit button.

    Thus, when the form is being submitted there $_POST['submit'] is set, but none of the other ones exist.

    So you need your HTML to be:

    <form action="contactus.php" method="POST">
        Name: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="text" size="32" value="" name="name"><br><br>
        E-Mail: &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="text" size="32" value="" name="header"><br><br>
        Subject: &nbsp;&nbsp;
        <input type="text" size="32" value="" name="subject"><br><br>
        Message: <br>
        <textarea rows="10" cols="40" name="message" value=""></textarea><br><br>
    
        <input type="submit" value="Submit" name="submit">
    </form>
    

    and contactus.php:

    <?php
    $to = 'some@email.com';
    if(isset($_POST['message']) && isset($_POST['header']) &&
       isset($_POST['subject']) && isset($_POST['submit']) &&
       @mail($to, $_POST['subject'], $_POST['message'], $_POST['header'])) {
        echo "Your message has been sent!";
    }else{
        echo "There has been a problem.";
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序