Php 发送电子邮件但抛出的电子邮件脚本无法重新声明spamcheck()错误
我有一个脚本,发送电子邮件到多个电子邮件地址,脚本是假设重定向到一个成功的页面完成后,电子邮件被发送没有问题,但我得到以下错误,而不是重定向 致命错误:无法重新声明spamcheck()(以前在中声明 /websites/123reg/LinuxPackage22/br/ig/ht/MYSITE.co.uk/public_html/admin/mailinglistsend.php:87) 在里面 /websites/123reg/LinuxPackage22/br/ig/ht/MYSITE.co.uk/public_html/admin/mailinglistsend.php 在线87 代码如下Php 发送电子邮件但抛出的电子邮件脚本无法重新声明spamcheck()错误,php,mysql,Php,Mysql,我有一个脚本,发送电子邮件到多个电子邮件地址,脚本是假设重定向到一个成功的页面完成后,电子邮件被发送没有问题,但我得到以下错误,而不是重定向 致命错误:无法重新声明spamcheck()(以前在中声明 /websites/123reg/LinuxPackage22/br/ig/ht/MYSITE.co.uk/public_html/admin/mailinglistsend.php:87) 在里面 /websites/123reg/LinuxPackage22/br/ig/ht/MYSITE.c
<?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');
?>
在do-while
循环中声明函数(为什么?!)。把它拿出来。一切都会好起来的 在do-while
循环中声明函数(为什么?!)。把它拿出来。一切都会好起来的 奇怪的是,您正在do while循环中声明函数
固定代码应该如下所示:
<?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');
?>
奇怪的是,您正在do while循环中声明函数
固定代码应该如下所示:
<?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');
?>
检查是否在任何包含的文件中声明了spamcheck()
函数
--更新
spamcheck函数位于while循环中。这就是重新声明的原因检查您是否已在任何包含的文件中声明了spamcheck()
函数
--更新
spamcheck函数位于while循环中。重新申报的原因是什么