dtdb99743 2015-07-10 11:31
浏览 16
已采纳

如何使这个PHP联系表格工作?

I got this free bootstrap temp for a restaurant. And I am trying to make my first contact form, but I have no idea how this works as it is so different from HMTL code.

I take it I have to change the PHP and put my own email address in it at $toEmail but when I try it and test it on XAMPP it does not work.

I have this for my PHP:

<?php
if (isset($_POST['submit'])) { 
  $name = $_POST['name'];
  $email = $_POST['email'];
  $ToEmail = 'test@test.com';
  $EmailSubject = $_POST['subject']; 
  $mailheader = "From: ".$_POST["email"]."
"; 
  $mailheader .= "Reply-To: ".$_POST["email"]."
"; 
  $mailheader .= "Content-type: text/html; charset=iso-8859-1
"; 
  $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
  $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
  $MESSAGE_BODY .= "Subject:".$_POST['subject']."<br />";  
  $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."<br>"; 
  if(mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader))
  {
  echo "<script>alert('Mail was sent !');</script>";
  echo "<script>document.location.href='http://localhost/restaurant/'</script>";
  }
  else
  {
  echo "<script>alert('Mail was not sent. Please try again later');</script>";
  }
 }

And this in my html

<div class="inner contact">
  <!-- Form Area -->
  <div class="contact-form">
    <!-- Form -->
    <form id="contact-us" method="post" action="contact.php">
      <!-- Left Inputs -->
      <div class="col-md-6 ">
        <!-- Name -->
        <input type="text" name="name" id="name" required class="form" placeholder="Naam" />
        <!-- Email -->
        <input type="email" name="email" id="email" required class="form" placeholder="Email Adres" />
        <!-- Subject -->
        <input type="text" name="subject" id="subject" required class="form" placeholder="Onderwerp" />
      </div><!-- End Left Inputs -->
      <!-- Right Inputs -->
      <div class="col-md-6">
        <!-- Message -->
        <textarea name="message" id="message" class="form textarea"  placeholder="Bericht"></textarea>
      </div><!-- End Right Inputs -->
      <!-- Bottom Submit -->
      <div class="relative fullwidth col-xs-12">
        <!-- Send Button -->
        <button type="submit" id="submit" name="submit" class="form-btn semibold">Verstuur Bericht</button> 
      </div><!-- End Bottom Submit -->
      <!-- Clear -->
      <div class="clear"></div>
    </form>
  </div><!-- End Contact Form Area -->             

Can someone please point me in the right direction? Which parts do i need to edit for it to work?

  • 写回答

2条回答 默认 最新

  • douwenpin0428 2015-07-13 12:39
    关注

    As an alternative to the Dhinju Divakarans answer, you can change the mail server settings to use an external mail server (e.g. gmail)

    I did this by editing the /xampp/sendmail/sendmail.ini. look for the following code and change the values. In my case the following works fine:

    smtp_server=smtp.googlemail.com
    auth_username= (put the gmail email address here)
    auth_password= your password
    hostname=smtp.googlemail.de
    

    I don't touched the other settings.

    Maybe you also want to have a look at this answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?