Email Form Redirect

after email is sent, redirect to...

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 9884 Views - Last Post: 30 December 2009 - 11:57 AM Rate Topic: -----

#1 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Email Form Redirect

Posted 28 December 2009 - 10:10 PM

OK, i have my form set up:



<form id="contactform" method="post" action="submitemail.php" >
					<fieldset>
						<label for="name">Name</label>
						<input type="text" name="name" id="name" onfocus="if(this.value=='Name')this.value='';" onblur="if(this.value=='')this.value='Name';" value="Name" />
						
						<label for="subject">Subject</label>
						<input type="text" name="subject" id="subject" onfocus="if(this.value=='Subject')this.value='';" onblur="if(this.value=='')this.value='Subject';" value="Subject" />
						
						<label for="email">Email Address</label>
						<input type="text" name="email" id="email" onfocus="if(this.value=='Email Address')this.value='';" onblur="if(this.value=='')this.value='Email Address';" value="Email Address" />
						
						<input type="submit" name="submit" id="submit" align="right" value="Submit" />
					</fieldset>
					<fieldset>
						<label for="question"></label>
					  <textarea id="question" name="question" rows="5" value="Message" cols="20" onfocus="if(this.value=='Message')this.value='';" onblur="if(this.value=='')this.value='Message';">Message</textarea>
					</fieldset>
					
				</form>




And the PHP functioning perfectly:



<?php
redirect( 'Location: http://rickbrossgraphics.com/Danny/index.php' );
?>

<?php

/************************
* Variables you can change
*************************/

$mailto = "zxcvzxcvzxcv@hotmail.com"; // Enter your mail addres here. 
$cc = "";
$bcc = "";
$subject = "From Your Website"; // Enter the subject here.

$vname = ucwords($_POST['name']); // Displays entered name in the "From" field of the e-mail.
								  // Replace with "Website contact form" etc (with quotes!) if 
								  // you don't want to display the name.


/************************
* do not modify anything below unless you know PHP/HTML/XHTML
*************************/


$email = $_POST['email'];

function validateEmail($email)
{
   if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
	  return true;
   else
	  return false;
}


if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['question']) < 1 ) || validateEmail($email) == FALSE){
	$emailerror .= '';

	if(strlen($_POST['name']) < 1 ){
		$emailerror .= '<span class="wrong">Please enter your name.</span>';
	}

	if(strlen($email) < 1 ){
		$emailerror .= '<span class="wrong">Please enter your e-mail address.</span>';
	}

	if(validateEmail($email) == FALSE) {
		$emailerror .= '<span class="wrong">Please enter a valid e-mail address.</span>';
	}

	if(strlen($_POST['question']) < 1 ){
		$emailerror .= '<span class="wrong">Please enter your message.</span>';
	}

} else {

		$emailerror .= "<span>Your message has been sent successfully. Thank you!</span>";

	// NOW SEND THE ENQUIRY

	$timestamp = date("F j, Y, g:ia");

	$messageproper ="\n\n" .
		"Name: " .
		ucwords($_POST['name']) .
		"\n" .
		"Email: " .
		$email .
		"\n" .
		"Subject: " .
		$_POST['subject'] .
		"\n" .
		"Comments: " .
		"\n" .
		$_POST['question'] .
		"\n" .
		"\n\n";

		$messageproper = trim(stripslashes($messageproper));
		mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['email'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['email'].">\nX-Mailer: PHP/" . phpversion() );

}
?>

<?php echo $emailerror; // Displays the error/success message. ?>







I just need to send the user back to index.php after the Email is sent.

Im guessing the

<?php
redirect( 'Location: http://rickbrossgraphics.com/Danny/index.php' );
?>


isn't appropriate or i need to do something in the "else" section by the email error thing...

This post has been edited by TechSupport: 28 December 2009 - 10:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Email Form Redirect

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Email Form Redirect

Posted 28 December 2009 - 10:18 PM

you can use header("Location: index.php");
for more information about header click the link
:)
Was This Post Helpful? 1
  • +
  • -

#3 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 28 December 2009 - 10:20 PM

where would i incorporate that into the .php files?

try sending a email through here: you'll see what happens when i put the <?php header("Location: index.php"); ?> at the top of the submitemail.php page.

This post has been edited by TechSupport: 28 December 2009 - 10:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Email Form Redirect

Posted 28 December 2009 - 10:29 PM

at the end of your code when mail sent
example:
$mail = @mail("$to","$subject","$message");
if($mail){
	header("Location: index.php");
}



:)
Was This Post Helpful? 0
  • +
  • -

#5 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 28 December 2009 - 10:43 PM

so at the end of

if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['question']) < 1 ) || validateEmail($email) == FALSE){
	$emailerror .= '';

	if(strlen($_POST['name']) < 1 ){
		$emailerror .= '<span class="wrong">Please enter your name.</span>';
	}

	if(strlen($email) < 1 ){
		$emailerror .= '<span class="wrong">Please enter your e-mail address.</span>';
	}

	if(validateEmail($email) == FALSE) {
		$emailerror .= '<span class="wrong">Please enter a valid e-mail address.</span>';
	}

	if(strlen($_POST['question']) < 1 ){
		$emailerror .= '<span class="wrong">Please enter your message.</span>';
	}

} else {



or at the end of submit.php? because neither works.
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Email Form Redirect

Posted 28 December 2009 - 10:52 PM

when your email sent
...
       "\n" .
        "Comments: " .
        "\n" .
        $_POST['question'] .
        "\n" .
        "\n\n";

        $messageproper = trim(stripslashes($messageproper));
        mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['email'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['email'].">\nX-Mailer: PHP/" . phpversion() );

}
?>
<?php echo $emailerror; // Displays the error/success message. ?>
<?PHP
// add script here to redirect
header("Location: index.php");
// or after a few seconds
header("refresh: 3; url= index.php"); // you can change seconds
?>



hope it helps :)
Was This Post Helpful? 0
  • +
  • -

#7 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 28 December 2009 - 10:59 PM

<span>Your message has been sent successfully. Thank you!</span>
Was This Post Helpful? 0
  • +
  • -

#8 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 28 December 2009 - 11:11 PM

i ment it doesn't even send that anymore...

ok i got the error/success message to show up, that was an error on my side. but i still cant get it to redirect.


this is what i have at the very end of the submitemail.php page:

<?php 

	echo $emailerror; // Displays the error/success message. 
	header("refresh: 3; url= index.php"); // you can change seconds
?>

This post has been edited by TechSupport: 28 December 2009 - 11:15 PM

Was This Post Helpful? 0
  • +
  • -

#9 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Email Form Redirect

Posted 28 December 2009 - 11:31 PM

<?PHP
OK here is some of your code when you are sending the email, now if it succeed then show thanks message and redirect to index.php page if not then show the error message
...
    $timestamp = date("F j, Y, g:ia");

    $messageproper ="\n\n" .
        "Name: " .
        ucwords($_POST['name']) .
        "\n" .
        "Email: " .
        $email .
        "\n" .
        "Subject: " .
        $_POST['subject'] .
        "\n" .
        "Comments: " .
        "\n" .
        $_POST['question'] .
        "\n" .
        "\n\n";

        $messageproper = trim(stripslashes($messageproper));
        mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['email'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['email'].">\nX-Mailer: PHP/" . phpversion() );

}
?>

<?php echo $emailerror; // Displays the error/success message. ?>


now assign mail() function to variable (mail() function is returning true value if succeed false if failed)
example:
$mail = @mail($mailto, $subject, $messageproper, ...);
        $messageproper = trim(stripslashes($messageproper));
        $mail = @mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['email'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['email'].">\nX-Mailer: PHP/" . phpversion() );
   	echo $messageproper;
	if($mail){
        header("Location: Address");
    }
}


Was This Post Helpful? 0
  • +
  • -

#10 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 28 December 2009 - 11:37 PM

ok did that, now i have:

	$messageproper ="\n\n" .
		"Name: " .
		ucwords($_POST['name']) .
		"\n" .
		"Email: " .
		$email .
		"\n" .
		"Subject: " .
		$_POST['subject'] .
		"\n" .
		"Comments: " .
		"\n" .
		$_POST['question'] .
		"\n" .
		"\n\n";

		$messageproper = trim(stripslashes($messageproper));
		$mail = @mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['email'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['email'].">\nX-Mailer: PHP/" . phpversion() );
		echo $messageproper;
		if($mail){
		header("Location: Address");
	}
}
?>



and it shows...

Name: Test Email: rickbross@rickbrossgraphics.com Subject: TEST
Comments: testtesttest
Your message has been sent successfully. Thank you!


instead of just ...

Your message has been sent successfully. Thank you!

and it still doesn't redirect.
Was This Post Helpful? 0
  • +
  • -

#11 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Email Form Redirect

Posted 28 December 2009 - 11:46 PM

Quote

and it still doesn't redirect.

did you changed the address to your url http://rickbrossgrap...Danny/index.php

<?php

/************************
* Variables you can change
*************************/

$mailto = "zxcvzxcvzxcv@hotmail.com"; // Enter your mail addres here.
$cc = "";
$bcc = "";
$subject = "From Your Website"; // Enter the subject here.

$vname = ucwords($_POST['name']); // Displays entered name in the "From" field of the e-mail.
                                  // Replace with "Website contact form" etc (with quotes!) if
                                  // you don't want to display the name.


/************************
* do not modify anything below unless you know PHP/HTML/XHTML
*************************/


$email = $_POST['email'];

function validateEmail($email)
{
   if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
      return true;
   else
      return false;
}


if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['question']) < 1 ) || validateEmail($email) == FALSE){
    $emailerror .= '';

    if(strlen($_POST['name']) < 1 ){
        $emailerror .= '<span class="wrong">Please enter your name.</span>';
    }

    if(strlen($email) < 1 ){
        $emailerror .= '<span class="wrong">Please enter your e-mail address.</span>';
    }

    if(validateEmail($email) == FALSE) {
        $emailerror .= '<span class="wrong">Please enter a valid e-mail address.</span>';
    }

    if(strlen($_POST['question']) < 1 ){
        $emailerror .= '<span class="wrong">Please enter your message.</span>';
    }

} else {

        $emailerror .= "<span>Your message has been sent successfully. Thank you!</span>";

    // NOW SEND THE ENQUIRY

    $timestamp = date("F j, Y, g:ia");

    $messageproper ="\n\n" .
        "Name: " .
        ucwords($_POST['name']) .
        "\n" .
        "Email: " .
        $email .
        "\n" .
        "Subject: " .
        $_POST['subject'] .
        "\n" .
        "Comments: " .
        "\n" .
        $_POST['question'] .
        "\n" .
        "\n\n";

        $messageproper = trim(stripslashes($messageproper));
        mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['email'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['email'].">\nX-Mailer: PHP/" . phpversion() );

}
?>

<?php
echo $emailerror; // Displays the error/success message. 
header("Location: [url="http://rickbrossgraphics.com/Danny/index.php");"]http://rickbrossgraphics.com/Danny/index.php");[/url]
?>


Was This Post Helpful? 0
  • +
  • -

#12 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 28 December 2009 - 11:58 PM

yeah i did and it still didn't work. my submitemail.php file looks exactly like that, andits still not redirecting.

see for yourself... http://rickbrossgrap...ges.php#contact
Was This Post Helpful? 0
  • +
  • -

#13 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Email Form Redirect

Posted 29 December 2009 - 12:49 AM

The way it is now it let's the user know when the message was sent successfully so why the need to redirect to a different page. When developing web applications the way it is now is the way I normally do it, I just let the user know the message was sent or whatever error happened when sending it. I dont redirect them to a different page. Just my opinion there :)
Was This Post Helpful? 0
  • +
  • -

#14 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 29 December 2009 - 01:05 AM

View PostPsychoCoder, on 28 Dec, 2009 - 11:49 PM, said:

The way it is now it let's the user know when the message was sent successfully so why the need to redirect to a different page. When developing web applications the way it is now is the way I normally do it, I just let the user know the message was sent or whatever error happened when sending it. I dont redirect them to a different page. Just my opinion there :)


because that's what my client wants, and the way ive always done this, has worked, now its not. i have no clue why.

Do you have any clue how i could make this happen or what i should tell him?
Was This Post Helpful? 0
  • +
  • -

#15 TechSupport  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 09-May 09

Re: Email Form Redirect

Posted 29 December 2009 - 01:32 AM

it worked with this code:

print "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2