我的PHP脚本是为了在前端向数据库中的成员输入一些新信息时发送电子邮件和短信。但是,电子邮件代码和SMS代码是单独工作的,但是当放在一起时代码没有被执行。
实际上跳过了代码。我尝试在被调用的函数中进行故意的错误,但它没有识别它。为什么呢?
<?php
error_reporting(E_ALL ^ E_NOTICE);
define('INCLUDE_CHECK', true);
require 'functions.php';
include ("generatesms.php");
include ("class.phpmailer.php");
include ("../sendsmsV3.5/sendsmsV3.5/CurlProcess.php");
include ("../sendsmsV3.5/sendsmsV3.5/Way2Sms.php");
include ("class.smtp.php");
// The above files can be included only if INCLUDE_CHECK is defined
$host = "localhost"; // Host name
$username = "root"; // Mysql username
$password = ""; // Mysql password
$db_name = "test"; // Database name
$tbl_name = "mails"; // Table name
// Connect to server and select database.
mysql_connect($host, $username, $password) or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
// Get values from form
$subject = $_POST['subject'];
$email = $_POST['email'];
$phone = $_POST['phone'];
//$dept = $_POST['dept'];
$content = $_POST['content'];
$month = $_POST['birthday-mm'];
$day = $_POST['birthday-dd'];
$year = $_POST['birthday-yyyy'];
$date_eve = "$year-$month-$day";
$dept = $_POST['branch'];
if (empty($dept)) {
echo("You didn't select any DEPEARTMENTS.");
} else {
$N = count($dept);
for($i=0; $i < $N; $i++) {
echo $dept[$i]; echo "<br>";
$dep = $dept[$i];
// Insert data into mysql
$sql = "INSERT INTO $tbl_name(subject, body, dept, phone, email, date_eve) VALUES ('$subject', '$content', '$dep', '$phone', '$email', '$date_eve')";
$result = mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if ($result) {
echo "Successful";
echo "<BR>";
newssender($dept, $content, $subject);
generatesms($dept,$date_eve,$subject);
echo "<a href='index.php'>Back to main page</a>";
} else {
echo "ERROR";
}
}
}
// close connection
mysql_close();
答案 0 :(得分:0)
首先,您的所有SQL都存在很大问题。您不应该使用mysql_ *函数,因为它们已被弃用,并且您没有对输入进行清理,从而使您面临漏洞。 (http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php)
如果您可以提出newssender()
功能代码,我可以给您一个详细/具体的答案,但与此同时,我将为其他用户提供一个通过一些调试过程的通用解决方案。
如果你有这样的代码:
myFunction1();
myFunction2();
且myFunction1()
已运行,但myFunction2()
不是,您可以尝试发表评论// myFunction1()
(听起来就是这样),此时如果myFunction2()
运行则显然问题出在myFunction1()
。以下是要寻找的内容:
die
或exit
。那些结束脚本,不再执行代码。测试#2的快速方法是:
myFunction1();
echo 'I made it here!';
如果你没有看到“我在这里做到了!”在你的屏幕上显然代码没有那么远,这意味着代码在从myFunction1()
我希望有所帮助!