Forum Moderators: coopster

Message Too Old, No Replies

navigation with switch

         

Malmo

10:33 pm on Nov 24, 2010 (gmt 0)

10+ Year Member



Hi guys!

I am creating a sending email system for my website and I have reached a problem. The sending system works fine, but the switch doesn´t.

After I send my email I the data of my default page is displayed and
not the data of the send.php file. I have pasted my 3 pages here so someone will recognize my problem and help me solve it.

The switch on index.php is setup like this:

<?php
$navigation = $_GET['page'];

switch($navigation) {

case "mail":
$content = "sendmail/mail.php";
break;

case "send":
$content = "sendmail/send.php";
break;

default:
$content = "index.php";
break;

}
include($content);
?>


The mail.php looks like this:

<?php
include ('mysql_connection.php');
$mailcount = 0;
$get = mysql_query ("SELECT * FROM mail WHERE send='1'");
echo "<h3>Send to:</h3>";
echo "<form action='index.php?page=send' method='GET'>";
while ($getrow = mysql_fetch_assoc($get)) {
echo "<input type='checkbox' name='mail_".$mailcount++."' value='".$getrow['email']."' CHECKED>".$getrow['email']."<br>";
}
echo "<br><br><p><b>Message:</b></p><textarea name=message cols=50 lines=7></textarea><br>
<input type=submit name=submit value=Send E-mail>";
echo "</form>";
?>


The send.php looks like this:
<?php
include ('mysql_connection.php');
ini_set ("SMTP", "mail.mydomain.com");

$headers = "From: info@mydomain.com";
$message = $_GET['message'];
for ($x=0;$x<count($_GET); $x++)
{
if ($_GET["mail_$x"])
{
$to = $_GET["mail_$x"];
$subject = "Hello";
$body = "$message";
mail($to, $subject, $body, $headers);
}
}
echo "The email was sent.Would you like to send another mail click<a href=index.php?page=mail>HERE</a>";
?>


When I click on send e-mail on my mail.php file I get a link like this:
index.php?mail_1=email%40mydomain.com&message=Test!&submit=Send
and the data of the index.php is shown and not the echo line where it comfirms that the mail has been sent from the send.php file. Hopefully someone understands my problem and I thank everyone that will give me advice or the solution to my problem.

Best regards.
Malmo.

Matthew1980

11:04 pm on Nov 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Malmo,

Looks like you need to do some basic debugging to me, start with the switch, and see that your getting the data through that is expected, and sanitise the input too - you can't be too careful!.

The sql statement, as it is using an int to get information from the db, doesn't need quoting, just doing this will be fine:-

$get = mysql_query ("SELECT * FROM `mail` WHERE `send` = 1 ");

quoted int's can cause all sorts of issues, as the sql engine converts quoted int's into string's.

For the mail() function to work correctly (satisfy the needed protocol) you will need to have the from: address in the headers, else this can also prevent the mail from being sent.

Maybe I read this wrong, but wouldn't it be better to just either have the includes within the case's of the switch, or actually echo the vars, your method seems a little convoluted to me.

Hope that makes sense anyway.

Cheers,
MRb

Malmo

8:27 am on Nov 25, 2010 (gmt 0)

10+ Year Member



Matthew1980 or MRB thank you for your advice, but I found the solution to my problem. I had to add a hidden field in the form with the switch values like this <input type=hidden name=page value=send> and now it works.

Best regards.
Malmo.

Matthew1980

11:16 am on Nov 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Malmo,

Well at least you have figured it out - hidden fields are a great way of doing some validation as you can set them to act as a dynamic thing pulled from a DB and check them post-submission.

Have fun with the rest of your project.

Cheers,
MRb