dtjo51649 2016-02-27 17:45
浏览 48

不会使用html和php表单发送到电子邮件

Not sure what i am doing wrong here but when i fill out my form and press submit i get the following error message... Cannot POST /form_process.php Thank you for your help.

      <form  method="post" name="contact_form" action="form_process.php">
    <br>
<p>Name:
<input name="name" type="text" id="name"><br>
        </p>     
<p>E-mail:
<input type="text" name="email" id="email">
        </p>
<p>Comment:
    <br><textarea type="text" name="comment" id="comment" > </textarea></p>
<p>
<input type="submit" value="Submit" name="submit" id="submit">

<input type="reset" value="Reset" id="reset">
</form>

And here is my php :

<?php
if ( isset( $_POST['submit'] ) )


$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$to = 'my email address goes here';
$subject = 'New Message';

 mail ( $to, $string $subject,$comment, "From " . $name);
echo "Your email has been sent";

?>
  • 写回答

1条回答 默认 最新

  • duanli0687 2016-02-27 18:25
    关注

    This doesn't work because there are several bugs in your code. Some missing ; and {}. Your mail function did also have a variable $string that certainly shouldn't be there. A fixed code would be:

    <?php
    if ( isset( $_POST['submit'] ) ){
    
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $comment = $_POST['comment'];
    
    $to = 'Your email address';
    $subject = 'New Message';
    
     mail ( $to,$subject,$comment, "From " . $name);
    echo "Your email has been sent";
    }
    ?>
    

    Please note that you have to have a mail server for this to work. You should also sent the variable $email with the email. More detailed answers to how to send an email with PHP can be found here: How to send an email using PHP?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题