cow1787 Posted June 24, 2008 Share Posted June 24, 2008 So I have a contact form on my website that I got from some tutorial site (I think, it's been a while). And it works well. You enter your Name, Email, Subject, and Message. When you send, it'll send to my email. After it sends the page is redirected to my homepage. Contact Page http://www.marklemmons.com/contact.html It's got a process.php that has the actual 'contact email server, etc' code in it, but I don't know php at all, that's why I'm here. (Will post process.php code at end) !!!!! So here's my problem. I just set up a mobile site with a contact page as well. And I want this same form on there so you can email me from your mobile device Mobile Contact Page http://mobile.marklemmons.com/contact.html So Now I have two forms, and they both work. (surprisingly...) But I want it to redirect you back to the mobile page if you sent the form From the mobile page. And it'll send you back to the regular page if you sent the form From the regular page. Right now it sends you back to the regular page no matter what. I'm assuming there's some kind of "if from mobile site, then go back to mobile site. else if from regular site, go back to regular site" but I'm not quite sure how to do it. <? $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message=$_POST['message']; $send = $_POST['Send']; if ($send == "Yes") { //Mail the comment /* Specify your SMTP Server, Port and Valid From Address */ ini_set("SMTP","mail.marklemmons.com"); ini_set("smtp_port","25"); ini_set("sendmail_from", "[email protected]"); //Specify where you want them email to be sent $to = '[email protected]'; $message = "Name: ".$name."\n Email: ".$email."\n Subject:".$subject."\n Message: ".$message; $headers = 'From: '.$email. "\r\n" . 'Reply-To: '.$email. "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("Location: http://www.marklemmons.com/"); } else { echo "you don't need to access this page directly"; } ?> Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/ Share on other sites More sharing options...
dmccabe Posted June 24, 2008 Share Posted June 24, 2008 Surely on the new form you change: header("Location: http://www.marklemmons.com/"); to header("Location: http://mobile.marklemmons.com/"); Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573307 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 But what if I'm using the same form? Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573315 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 I guess having a 2nd process.php file works (just tried it) but Is there a way to have it redirect specifically in one? Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573342 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 you could detect the host and then send based on that. the host would be mobile.site.com for the mobile one. to detect the host do $_SERVER['HTTP_HOST']; Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573355 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks. Nooow how exactly would I implement this into my code? Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573440 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 if($_SERVER['HTTP_HOST'] == http://usersite.com) { //code here header("Location:wherever") } if($_SERVER['HTTP_HOST'] == http://mobile.usersite.com) { //code here header("Location:wherever") } Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573449 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks for helping. New Code with the changes at the end... Except I get an error instead of a redirect to my page. "Parse error: syntax error, unexpected ':' in /home/markl7/public_html/process.php on line 26" Line 26 is "if($_SERVER['HTTP_HOST'] == http://www.marklemmons.com)" <? $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message=$_POST['message']; $send = $_POST['Send']; if ($send == "Yes") { //Mail the comment /* Specify your SMTP Server, Port and Valid From Address */ ini_set("SMTP","mail.marklemmons.com"); ini_set("smtp_port","25"); ini_set("sendmail_from", "[email protected]"); //Specify where you want them email to be sent $to = '[email protected]'; $message = "Name: ".$name."\n Email: ".$email."\n Subject:".$subject."\n Message: ".$message; $headers = 'From: '.$email. "\r\n" . 'Reply-To: '.$email. "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); if($_SERVER['HTTP_HOST'] == http://www.marklemmons.com) { //code here header("Location: http://www.marklemmomns.com") } if($_SERVER['HTTP_HOST'] == http://mobile.marklemmons.com) { //code here header("Location: http://mobile.marklemmons.com") } else { echo "you don't need to access this page directly"; } ?> Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573458 Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 Check the lines above and below line 26 for any colons. Sometimes I accidently type a colon instead of a semicolon at the end of a line. Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573462 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 put a ; at the end of the header Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573467 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Just added the ; at the end of the header, still nothing. same error. The only colon is in "http://" on line 26. 25 is empty and 27 is "{" does my site link need to be in ' or " on line 26 and 31? if($_SERVER['HTTP_HOST'] == http://www.marklemmons.com) if($_SERVER['HTTP_HOST'] == http://mobile.marklemmons.com) Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573473 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 yes the link should be in "site link" soz should of said Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573476 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Here's the updated code. (see bottom) With it like this, I get another error... Parse error: syntax error, unexpected T_ELSE in /home/markl7/public_html/process.php on line 36 So I took out the code at the end as I'm not really sure what it's for. Was in the tutorial. Do I need it? What's it do? else { echo "you don't need to access this page directly"; } and then I got Parse error: syntax error, unexpected $end in /home/markl7/public_html/process.php on line 37 I did however get it to somewhat work. I left an extra "}" at the end before ?> and it went through. except on both forms (regular and mobile) it goes back to the mobile page. <? $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message=$_POST['message']; $send = $_POST['Send']; if ($send == "Yes") { //Mail the comment /* Specify your SMTP Server, Port and Valid From Address */ ini_set("SMTP","mail.marklemmons.com"); ini_set("smtp_port","25"); ini_set("sendmail_from", "[email protected]"); //Specify where you want them email to be sent $to = '[email protected]'; $message = "Name: ".$name."\n Email: ".$email."\n Subject:".$subject."\n Message: ".$message; $headers = 'From: '.$email. "\r\n" . 'Reply-To: '.$email. "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); if($_SERVER['HTTP_HOST'] == "http://www.marklemmons.com"); { //code here header("Location: http://www.marklemmomns.com"); } if($_SERVER['HTTP_HOST'] == "http://mobile.marklemmons.com"); { //code here header("Location: http://mobile.marklemmons.com"); } else { echo "you don't need to access this page directly"; } ?> Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573483 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 echo out the host and see what it says on each one Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573484 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 ? Total php noob here, so I have no idea how to do that. Haha Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573487 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 echo $_SERVER['HTTP_HOST']; Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573498 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 like this? echo $_SERVER['HTTP_HOST']; == "http://www.marklemmons.com"); { //code here header("Location: http://www.marklemmomns.com"); } echo $_SERVER['HTTP_HOST']; == "http://mobile.marklemmons.com"); { //code here header("Location: http://mobile.marklemmons.com"); } else { echo "you don't need to access this page directly"; } That gives me "Parse error: syntax error, unexpected T_IS_EQUAL in /home/markl7/public_html/process.php on line 28" Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573500 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 no sorry like this echo $_SERVER['HTTP_HOST']; this will tell you what the host is, then we will go from there Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573503 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Where do I put that? Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573529 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 any where in the php, then run the php and tell me what it says Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573546 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Placed it at the top.Uploaded it, then went to it And again I got Parse error: syntax error, unexpected T_ELSE in /home/markl7/public_html/process.php on line 40 <? echo $_SERVER['HTTP_HOST']; $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message=$_POST['message']; $send = $_POST['Send']; if ($send == "Yes") { //Mail the comment /* Specify your SMTP Server, Port and Valid From Address */ ini_set("SMTP","mail.marklemmons.com"); ini_set("smtp_port","25"); ini_set("sendmail_from", "[email protected]"); //Specify where you want them email to be sent $to = '[email protected]'; $message = "Name: ".$name."\n Email: ".$email."\n Subject:".$subject."\n Message: ".$message; $headers = 'From: '.$email. "\r\n" . 'Reply-To: '.$email. "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); if($_SERVER['HTTP_HOST'] == "http://www.marklemmons.com"); { //code here header("Location: http://www.marklemmomns.com"); } if($_SERVER['HTTP_HOST'] == "http://mobile.marklemmons.com"); { //code here header("Location: http://mobile.marklemmons.com"); } else { echo "you don't need to access this page directly"; } ?> Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573559 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 remove the else { } statment Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573569 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 Parse error: syntax error, unexpected $end in /home/markl7/public_html/process.php on line 43 haha, it's a never ending circle of errors Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573574 Share on other sites More sharing options...
DeanWhitehouse Posted June 24, 2008 Share Posted June 24, 2008 lol ,ok , now i see add a } just before ?> Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573575 Share on other sites More sharing options...
cow1787 Posted June 24, 2008 Author Share Posted June 24, 2008 www.marklemmons.com is what it says. which is my correct host. woohoo...one thing worked Link to comment https://forums.phpfreaks.com/topic/111696-contact-form-redirect-to-seperate-sites/#findComment-573580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.