dtrpv60860 2013-08-29 04:51
浏览 79

表格不发送电子邮件

I am having trouble sending the information from my PHP form to the email address. I am fairly new to PHP. Code is below:

if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$myEmail = "shivambh28@gmail.com";

if (empty($name) || empty($subject) || empty($message)) {
  $error = 'Please make sure to double check the fields for errors.';
} elseif (!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
  $error = 'Email is incorrect';
} else {
  $headers .= "From: $email
";
  $headers .= "Reply-To: $myEmail
";
  $headers .= "Return-Path: $myEmail
";
  $headers .= "CC: $email
";
  $headers .= "BCC: $myEmail
";

  if ( mail($to,$subject,$message,$headers) ) {
    $to = $myEmail;
    $subject = $subject;
    $message = $message;
    $from = $email;
    $headers = "From:" . $from;
    echo "Mail Sent.";
  } else {
    echo 'failure to send email';
  }
}
}

HTML:

<form id="contactForm" class="form-horizontal" action="<?php echo get_option('home'); ?>/email/"  method="POST">
    <input id="name" name="name" placeholder="Full Name" type="text">
    <input id="subject" name="subject" placeholder="Subject" type="text">
    <input id="email" name="email" placeholder="Email Address" type="email">
    <textarea placeholder="Your Message" id="message" name="message" rows="10"></textarea>
    <input type="submit" value="SEND" class="btn btn-primary btn-block">
</form>

NOTE: I am using WP CMS.

  • 写回答

6条回答 默认 最新

  • doudiandi6967 2013-08-29 04:53
    关注

    Your form is missing the method attribute. edit the code so that your form has method POST.

    <form id="contactForm" class="form-horizontal" action="contact.tpl.php" method="POST">
    

    secondly remove one of your mail function calls. if not your email will be sent twice

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看