【问题标题】:How to make a send yourself a copy check box如何让自己发送一份副本复选框
【发布时间】:2013-06-17 04:21:11
【问题描述】:

我需要一个可以向自己发送副本的复选框。例如,他们填写了联系表格并希望将副本发送给他们自己,他们选中该框,它将通过电子邮件发送给我,并且仍然通过电子邮件发送给他们。这是我的 PHP:

 //If the form is submitted
  if(isset($_POST['submit'])) {

    //Check to make sure that the name field is not empty
    if(trim($_POST['contactname']) == '') {
      $hasError = true;
    } else {
      $name = trim($_POST['contactname']);
    }

    //Check to make sure that the subject field is not empty
    if(trim($_POST['subject']) == '') {
      $hasError = true;
    } else {
      $subject = trim($_POST['subject']);
    }

    //Check to make sure that the subject field is not empty
    if(trim($_POST['weburl']) == '') {
      $site = trim($_POST['weburl']);
    }

    //Check to make sure sure that a valid email address is submitted
    if(trim($_POST['email']) == '')  {
      $hasError = true;
    } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
      $hasError = true;
    } else {
      $email = trim($_POST['email']);
    }

    //Check to make sure comments were entered
    if(trim($_POST['message']) == '') {
      $hasError = true;
    } else {
      if(function_exists('stripslashes')) {
        $comments = stripslashes(trim($_POST['message']));
      } else {
        $comments = trim($_POST['message']);
      }
    }

    //If there is no error, send the email
    if(!isset($hasError)) {
      $emailTo = 'myemail@domain.com'; // Put your own email address here
      $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nSite:  \n\nComments:\n $comments";
      $headers = 'From: BTSyncrets Contact <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

      mail($emailTo, $subject, $body, $headers);
      $emailSent = true;
    } 
  }

这是我的联系表格代码:

<div id="contact" class="offset4 login">
        <form style="margin-top: 5% !important;" method="post" action="index.php" id="contactform">
          <fieldset class="well">
            <br>

            <div class="clearfix">
              <label for="name">
                Your Name<span class="help-required">*</span>
              </label>
              <div class="input">
                <input type="text" id="boxblack" name="contactname" id="contactname" value="" class="span6 required" role="input" aria-required="true" />
              </div>
            </div>


            <div class="clearfix">
              <label for="email">
                Your Email<span class="help-required">*</span>
              </label>
              <div class="input">
                <input type="text" id="boxblack" name="email" id="email" value="" class="span6 required email" role="input" aria-required="true" />
              </div>
            </div>

            <div class="clearfix">
              <label for="weburl">
                Your Website
              </label>
              <div class="input">
                <input type="text" id="boxblack" name="weburl" id="weburl" value="" class="span6 required url" role="input" aria-required="true" />
              </div>
            </div>


            <div class="clearfix">
              <label for="subject">
                Subject<span class="help-required">*</span>
              </label>
              <div class="input">
                <select name="subject" id="boxblack" id="subject" class="span6 required" role="select" aria-required="true">
                  <option></option>
                  <option>One</option>
                  <option>Two</option>
                </select>
              </div>
            </div>

            <div class="clearfix">
              <label for="message">Message<span class="help-required">*</span></label>
              <div class="input">
                <textarea rows="8" id="boxblack" style="resize: none;" name="message" id="message" class="span6 required" role="textbox" aria-required="true"></textarea>
              </div>
            </div>


            <label class="checkbox">
              <input type="checkbox" name="copy" value="1" /> Send Yourself a copy
            </label>


            <div class="actions">
              <input type="submit" value="Send Your Message" name="submit" id="submitButton" class="btn btn-inverse" title="Click here to submit your message!" />
              <input type="reset" value="Clear Form" class="btn btn-danger" title="Remove all the data from the form." />
            </div>
          </fieldset>
        </form>
      </div><!-- form -->

【问题讨论】:

  • 好久不见,eregi
  • 或密件抄送或抄送到标题
  • @OneTrickPony 我收到一条错误消息,指出if isset($_POST['copy']) 所在的行,@Dagon 我该怎么做?对不起,我是 PHP 新手

标签: php html checkbox contact-form


【解决方案1】:

请参阅下面的Add this 评论。

//If there is no error, send the email
if(!isset($hasError)) {
  $emailTo = 'myemail@domain.com'; // Put your own email address here
  $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nSite:  \n\nComments:\n $comments";
  $headers = 'From: BTSyncrets Contact <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

// Add this
  if (isset($_POST['copy'])) {
      $headers .= "\nBcc: myemailaddress@example.com";
  }

  mail($emailTo, $subject, $body, $headers);
  $emailSent = true;
} 

【讨论】:

  • 这是说我在第 162 行遇到错误,但这是结束 HTML 标记
  • 错误是什么?如果您删除我的补丁,错误会消失吗?
  • 是的,这是错误Parse error: syntax error, unexpected $end in /home/nickfost/public_html/sites/btsyncrets/pages/contact/index.php on line 162页面是白色的,这是唯一的东西
  • 该错误通常是缺少右括号的症状。如果您确定您已经准确地复制了我的补丁,并且您仍然收到错误,我将不得不在我的开发服务器上进行设置并在那里仔细检查。这需要一段时间 - 我还没吃早餐!
猜你喜欢
  • 2012-06-23
  • 2021-06-03
  • 1970-01-01
  • 2021-03-24
  • 1970-01-01
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
  • 2017-04-18
相关资源
最近更新 更多