Javascript PhP邮件在新项目中无效

时间:2014-11-14 10:29:49

标签: javascript php html html5

我正在尝试将过去项目中的旧邮件脚本集成到我的新站点。该过程涉及以下列方式的javascript和php脚本。

    <script type="text/javascript">
  function send_mail() {
      var subject = document.getElementById('subject').value;
      var message = document.instanceById('message').getContent();
      var params = 'subject='+subject+'&message='+message;
      if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
      else { xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); }
      xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('result').innerHTML=xmlhttp.responseText; }
      }
      document.getElementById('result').innerHTML = 'Message is sending.. please wait..';
      xmlhttp.open('POST', 'scripts/newsletter-mail.php', true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", params.length);
      xmlhttp.setRequestHeader("Connection", "close");
      xmlhttp.send(params);
  }
</script>

表格:

    <label><strong>Title</strong></label>                               
                <input type="text" name="subject" id="subject" class="form-control" value="">
                <br>
                    </div>  
            <div class="col-md-12">                     
              <label><strong>Main Text</strong></label>
<textarea class="summernote" id="text" name="message" id="message" data-plugin-summernote data-plugin-options='{ "height": 300, "codemirror": { "theme": "ambiance" } }'></textarea>
<input class="button" type="submit" id="submit" name="submit" value="Send Email" onclick="send_mail();" />

php脚本

     @error_reporting(E_ALL & ~E_NOTICE);
  session_cache_limiter('nocache, must-revalidate');
  session_start();


  include_once '../../scripts/mysql.lib.php';
  $mysql = new mysql(TRUE);

$serv = $mysql->fetch("SELECT * FROM server ;", FALSE); 
$host = $serv['host'];


  $limit = 100;

  $subject = $_POST['subject'];
  $message = $_POST['message'];
  $headers[] = 'From: My Address';
  $headers[] = 'X-Priority: 5';
  $headers[] = 'MIME-Version: 1.0';
  $headers[] = 'Content-Type: text/html; charset="utf-8"' . "\r\n";
  $hlist = implode("\r\n", $headers);

  $result = 1;
  $list = $mysql->fetch('SELECT COUNT(*) AS count FROM newsletter;', FALSE);
  $count = $list['count'];
  $emails = $mysql->fetch("SELECT email_id, email FROM newsletter WHERE status = 'none' LIMIT $limit;", TRUE);
  if ($mysql->num_rows > 0) {
      $sent = array();
      $error = array();
      foreach($emails as $email) {
          $msg = $message . "\r\n<br /><br />" . '<small>If you wish to unregister from our newsletter list please click  <a href="'.$host .'/unsubscribe.php?email=' . $email['email'] . '&code=' . $email['code'] . '">Here</a></small>';
          if (@mail($email['email'], $subject, $msg, $hlist)) { $sent[] = $email['email_id']; }
          else { $error[] = $email['email_id']; }
          unset($msg);
      }
      $updsent = $mysql->query("UPDATE newsletter SET status = 'sent' WHERE email_id IN('" . implode("','",$sent) . "');");
      $upderror = $mysql->query("UPDATE newsletter SET status = 'error' WHERE email_id IN('" . implode("','",$error) . "');");
      switch(TRUE) {
          case (count($error) == 0): $result = 3; break;
          case (count($error) == $mysql->num_rows): $result = 4; break;
          case (count($error) > 0): $result = 5; break;
      }
  }
  if (($result == 1) && ($count > 0)) { $result = 2; }

  switch($result) {
      case 1: echo 'No Email Address in List - Message was not sent.'; break;
      case 2: echo 'All User have received the Message'; break;
      case 3: echo 'Message Sent!<br />(Cont. Sending  ..)'; break;
      case 4: echo 'Error - Message was not sent.'; break;
      case 5: echo 'Message Sent to some User.<br />(Cont. Sending..)'; break;
  }


?>

在表单上方的Html中,存在一个div来获取结果。

简而言之,在将代码迁移到我的项目之后,没有任何东西可以工作。没有发送任何内容,结果div中没有​​结果,我的URL栏会返回以下内容:

newsletter-mail.php?subject=This is a title &message=<p>This is a test message<%2Fp>&submit=Send+Email

任何想法都将受到赞赏。

0 个答案:

没有答案