Hi, I need some help to do the folowing: If the message is sent users are redirected to one page, and if for some reason (missing email,...) they are redirected to another. Here's the code i have right now: (it works, but it shows a message on the page itself) <?php if(($_POST['email'] == '') || ($_POST['name'] == '') || (is_numeric($_POST['name'])) || ($_POST['surname'] == '') || (is_numeric($_POST['surname'])) || ($_POST['subject'] == '') || ($_POST['message'] == '')) { echo 'Complete the forms correctly <br> Click <a href="index.php">here</a> to return on main page.'; } else { $to = 'mail@mail.com'; $send_date = date('d-m-Y H:i:s'); $subject = $_POST['subject']; $message = ' <html> <head> <title>Contact</title> </head> <body> <p><tt>Data trimitere: '.$send_date.' </tt></p> <table> <tr> <td><tt> Name: '.$_POST['name'].' </tt></td> </tr> <tr> <td><tt> Surname: '.$_POST['surname'].' </tt></td> </tr> <tr> <td><tt> E-Mail: <a href="mailto:'.$_POST['email'].'">'.$_POST['email'].'</a> </tt></td> </tr> <tr> <td><tt> Message: <br><br> '.$_POST['message'].' </tt></td> </tr> </table> </body> </html>'; $headere = "MIME-Version: 1.0\r\n"; $headere .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headere .= "From: ".$_POST['name']." ".$_POST['surname']."<".$_POST['email'].">\r\n"; mail($to, $subject, $message, $headere); echo 'The message was send'; } ?> Code (markup): Thank you
If you want to automaticly redirect users to another page, try php command like this: header( 'Location: http ://www.site.com/page.html'); But there must be no other output sent to user before this line.
if (mail($to, $subject, $message, $headere)) { h e a d e r('Location: http ://www.site.com/page.html'); exit; }
As shown above, you can use return value from mail function to see if it was sent. http://php.net/manual/en/function.mail.php