douyan5481 2012-11-05 15:58
浏览 68
已采纳

电子邮件脚本发送电子邮件但丢弃无法重新声明spamcheck()错误

I have a script that send emails to multiple email addresses, the script is suppose to redirect to a success page upon completion, the emails are being sent fine with no problems, however I am getting up the following error instead of redirection.

Fatal error: Cannot redeclare spamcheck() (previously declared in /websites/123reg/LinuxPackage22/br/ig/ht/MYSITE.co.uk/public_html/admin/mailinglistsend.php:87) in /websites/123reg/LinuxPackage22/br/ig/ht/MYSITE.co.uk/public_html/admin/mailinglistsend.php on line 87

The code is as follows

<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

require_once('../Connections/BrightLights.php'); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_BrightLights, $BrightLights);
$query_mailinglist = "SELECT * FROM mailing_list WHERE subscribed = ''";
$mailinglist = mysql_query($query_mailinglist, $BrightLights) or die(mysql_error());
$row_mailinglist = mysql_fetch_assoc($mailinglist);
$totalRows_mailinglist = mysql_num_rows($mailinglist);

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);




?>
<?php 



$subject = $_POST['subject'];
$body = $_POST['body'];

do {

$name = $row_mailinglist['name'];
$email = $row_mailinglist['email'];



    $email_from = 'mailinglist@MYSITE.com';
    $email_subject = "$subject";
    $email_body = "
    $name,

    $body



    You have received this email because you have subscribed via our website, to unsubscribe go to MYSITE/mailing-list.php?unsubscribe=$email";


    $to = "$email";
    $headers = "From: $email_from";
    mail($to, $email_subject, $email_body, $headers);





    function spamcheck($field)
    {
        //filter_var() sanitizes the e-mail
        //address using FILTER_SANITIZE_EMAIL
        $field=filter_var($field, FILTER_SANITIZE_EMAIL);

        //filter_var() validates the e-mail
        //address using FILTER_VALIDATE_EMAIL
        if(filter_var($field, FILTER_VALIDATE_EMAIL))
        {
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

    } while ($row_mailinglist = mysql_fetch_assoc($mailinglist));


mysql_free_result($mailinglist);

    header('Location: mailinglist-new.php?sent');

?>

I appreciate your help :-)

  • 写回答

3条回答 默认 最新

  • douhuan3448 2012-11-05 16:03
    关注

    strange you are declaring function inside of do while loop

    fixed code should look something like this:

    <?php
    //initialize the session
    if (!isset($_SESSION)) {
      session_start();
    }
    
    require_once('../Connections/BrightLights.php'); 
    
    function spamcheck($field)
        {
            //filter_var() sanitizes the e-mail
            //address using FILTER_SANITIZE_EMAIL
            $field=filter_var($field, FILTER_SANITIZE_EMAIL);
    
            //filter_var() validates the e-mail
            //address using FILTER_VALIDATE_EMAIL
            if(filter_var($field, FILTER_VALIDATE_EMAIL))
            {
                return TRUE;
            }
            else
            {
                return FALSE;
            }
        }
    
    
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    mysql_select_db($database_BrightLights, $BrightLights);
    $query_mailinglist = "SELECT * FROM mailing_list WHERE subscribed = ''";
    $mailinglist = mysql_query($query_mailinglist, $BrightLights) or die(mysql_error());
    $row_mailinglist = mysql_fetch_assoc($mailinglist);
    $totalRows_mailinglist = mysql_num_rows($mailinglist);
    
    error_reporting(E_ALL & ~E_NOTICE);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
    
    
    
    
    
    
    $subject = $_POST['subject'];
    $body = $_POST['body'];
    
    do {
    
    $name = $row_mailinglist['name'];
    $email = $row_mailinglist['email'];
    
    
    
        $email_from = 'mailinglist@brightlightstheatreschool.com';
        $email_subject = "$subject";
        $email_body = "
        $name,
    
        $body
    
    
    
        You have received this email because you have subscribed via our website, to unsubscribe go to brightlightstheatreschool.com/mailing-list.php?unsubscribe=$email";
    
    
        $to = "$email";
        $headers = "From: $email_from";
        mail($to, $email_subject, $email_body, $headers);
    
        } while ($row_mailinglist = mysql_fetch_assoc($mailinglist));
    
    
    mysql_free_result($mailinglist);
    
        header('Location: mailinglist-new.php?sent');
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料