<?php if(!$_POST) exit; $email = $_POST['email']; if($errors==1) echo $error; else{ $values = array ('name','message'); $required = array('name','message'); $your_email = "email@address"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'name') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo '<-------Here I guess---------------->'; } else { echo 'ERROR!'; } } ?> Code (markup): How can i make this code call a url or redirect to URL on successful submit? Thanks
you can use header function to redirect (assuming no output is sent during the form process) header("Location:http://redirecturl.com");
This will do: <?php if(!$_POST) exit; $email = $_POST['email']; if($errors==1) echo $error; else{ $values = array ('name','message'); $required = array('name','message'); $your_email = "email@address"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'name') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { header('location:redirect_here'); } else { echo 'ERROR!'; } } ?> PHP:
Replace "redirect_here" wwith the page where you want to redirect your user in this line: header('location:redirect_here'); PHP:
Well i got this Warning: Cannot modify header information - headers already sent by (output started at /888/8888/public_html/8888/contact.php:1)
You need to make sure that there is no output before you modify the header, that includes white spaces as well.. Have you used the code I provided, or the code in your original post?