-4

My PHP script was written to send email and SMS when some new information is entered in the front end to members in database. However the email code and SMS code are working individually, but when put together the code is not getting executed.

The code in fact skipped. I tried making a deliberate error in the called function but it did not recognize it. Why?

<?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();
chrislondon
  • 12,487
  • 5
  • 26
  • 65

1 Answers1

0

Firstly you have a big problem with all of your SQL. You shouldn't use mysql_* functions as they are deprecated and you're not sanitizing your inputs leaving you exposed to vulnerabilities. (http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php)

If you could pose your newssender() function code I can give you a detailed/specific answer but in the meantime I will give a general solution that goes through some debugging processes for other users.

if you have code like this:

myFunction1();
myFunction2();

and myFunction1() is run but myFunction2() is NOT, you can try commenting out // myFunction1() (which it sounds like you did) and at that point if myFunction2() runs then obviously the problem resides in myFunction1(). Here are the things to look for:

  1. Fatal errors. Make sure you have errors and notices turned on to find syntax or other errors in your code
  2. Look for any die or exit that may exist in your code. Those end the script and no more code is executed.

A quick way to test #2 is to do this:

myFunction1();
echo 'I made it here!';

If you don't see "I made it here!" on your screen then obviously the code didn't get that far, meaning the code ended before it returned from myFunction1()

I hope that helps!

chrislondon
  • 12,487
  • 5
  • 26
  • 65