douqiao7958 2016-02-23 15:01
浏览 31
已采纳

如何在html联系表单中的提交按钮上配置电子邮件地址

I am unable to configure my email address on the submit button in this piece of code:

<div id="contact" class="spacer">

<div class="container contactform center">
<h2 class="text-center  wowload fadeInUp">Get in touch with us</h2>
  <div class="row wowload fadeInLeftBig">
      <div class="col-sm-6 col-sm-offset-3 col-xs-12">
        <form class="cmxform" id="commentForm" method="post" action="email.php">
        <fieldset>
        <input type="text" placeholder="Subject" id="csubject" name="subject" minlength="2" type="text" required>
        <input type="text" placeholder="Email" id="cemail" type="email" name="email" required>
        <textarea rows="5" placeholder="Message" id="ccomment" name="comment" required></textarea>
        <input class="submit  btn btn-primary" type="submit" value="Submit">
        </fieldset>
    </form>
      </div>
  </div>

I tried linking it to a php page (email.php), but it says server error. I don't know what to do. Can someone please help me?

  • 写回答

1条回答 默认 最新

  • dongpalou5352 2016-02-23 15:32
    关注

    To send an email you need the mail() function http://php.net/manual/en/function.mail.php

    With your code you need to name the submit like name="submit" then inside action.php file you have to write something like this (or inside the same php where you have this code):

    if(isset($_POST["submit"]))
    {
    //Remember to do input validations
    $subject = $_POST["subject"];
    $from = $_POST["email"];
    $comment = $_POST["comment"];
    $body = "User with email $from send the next comment: $comment";
    
    
    //then here you set your email
    
    $to = "myemail@email.com"; //change this
    mail($to,$subject,$body);
    }
    

    This is only to explain some basic usage and set the variables you need, I advice you read also PHPmailer class

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器