0

I am making a page that uses a login and contact page.

Everything is working fine, but I have a small hiccup at one point.

The scenario is:
When the user isn't logged in, the contact form is to be filled completely and will be sent to a particular email.
But when the user is logged in, the page reads from the mysql database to fetch username and email (auto fill in fields of contact form), and sends it to some other email id (other than the one when not logged in).

I am using a session variable 'account' to check whether the user is logged in or not.

Here is the code: (The problem is somewhere in lines 28 - 35)

<?php
	
	session_start();
	if($_POST)
	{
		require_once('recaptchalib.php');
	  	$privatekey = "********";
		$resp = recaptcha_check_answer ($privatekey,
		                                $_SERVER["REMOTE_ADDR"],
		                                $_POST["recaptcha_challenge_field"],
		                                $_POST["recaptcha_response_field"]);

		if (!$resp->is_valid) {
		  	echo "recaptchaerror";
		} 
		else {
		        $name = $_POST['name'];
			$email = $_POST['eid'];
			$subject =  $_POST['sub'];
			$message = $_POST['msg'];
			$from = "*********";
			$ip = getenv("REMOTE_ADDR");
			$headers = "From: {$from}\r\n";
			$headers .= "MIME-Version: 1.0\r\n";
			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
			

			$to = "";
			if($_SESSION['account'] != "1") {
				$to .= "test123@gmail.com";
			}
			else //when $_SESSION['account'] == "1"
                        {
				$to .= "anothertest123@gmail.com";
			}


			$sub = "Server Site Contact Form";
			$msg = $message;
			if(mail($to, $sub, $msg, $headers))
				echo "success";
			else
				echo "mailererror";
		}	
	}
?>

The problem is when the user isn't logged in, it sends the mail correctly to test123@gmail.com. But if the user is logged in, it does not send an email to anothertest123@gmail.com, but still shows "success".

What am I doing wrong??
Any help is appreciated. Thanks.

P.S. - I am new to PHP, so excuse me, if you find the code a bit lame (to say).

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by nice123
0

have you tried taking out the NOT operator ! and switch the email address' in the if statement

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.