Jump to content

Link in New window with PHP


DizzyDan

Recommended Posts

Basically i have a form on the front of the webpage that when you submit send the information to my e-mail all via PHP.WebPageWhen you submit the information is sends you to a thank you page, as usual.PHP

<?php$myemail  = "dizzydan@rocketmail.com";$subject = "Mailing List";$message = "E-mail: $email";mail($myemail, $subject, $message);header('Location: thankyou.html');exit();?>

What i want to do is have the thank you page open in a new window. Is this possible with php? i searched couldnt find anything. If this is not possible, is there a way i could have the thank you page automatically redirect back to the main page?

Link to comment
Share on other sites

i dont think it is possible with php..i guess it is possible with js...

If this is not possible, is there a way i could have the thank you page automatically redirect back to the main page?
you may do html redirection in <meta> tag in your thank you page..to do a redirect after some time.
Link to comment
Share on other sites

Ok, two things,1. When i tested the code i created its own page, then when i got it to work i placed the code in to the main page but now it doesn't send an e-mail.2. Could you show me exactly in my code how to make it open up a new window for the thankyou page?default.html

<!-- !!!!!!!!!!Mailing List!!!!!!!!!! -->	<div id="mailinglist">		<form action="contact.php" method="post">		<b>Stay Updated, Sign Up!		<br />E-mail:</b>		<input type="text" name="email" size="13" />		<input type="submit" value="Submit" />		</form>			</div><!-- !!!!!!!!!!END Mailing List!!!!!!!!!! -->

contact.php

<?php$myemail  = "dizzydan@rocketmail.com";$subject = "Mailing List";$message = "E-mail: $email";mail($myemail, $subject, $message);header('Location: thankyou.html');exit();?>

Link to comment
Share on other sites

default.html

<!-- !!!!!!!!!!Mailing List!!!!!!!!!! -->	<div id="mailinglist">		<form action="contact.php" method="post" target="_blank">		<b>Stay Updated, Sign Up!		<br />E-mail:</b>		<input type="text" name="email" size="13" />		<input type="submit" value="Submit" />		</form>			</div><!-- !!!!!!!!!!END Mailing List!!!!!!!!!! -->

contact.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Thank you for subscribing to my mailing list</title></head><body><?php$myemail  = "dizzydan@rocketmail.com";$subject = "Mailing List";$message = "E-mail: ".$_REQUEST['email'];$succes = mail($myemail, $subject, $message);//note: your message could be stored in a separate file and you'd just grab the content of the file// ex.: $msg = file_get_contents('thankyou.html');$msg = '<h1>Thank you for subscribing to my mailing list!</h1><p>Thank you thank you thank you! I will not let you down! :p </p>';if(!$succes)	echo '<p>Failure in adding you to mailing list - please contact me on email <a href="mailto:'.$myemail.'">'.$myemail.'</a></p>';else	echo $msg;?></body>

contact.php should be a proper page - you don't need to redirect to a different page to display the thank you message. If you wanted you could instead redirect to your index-page (for instance) after a set amount of seconds.

Link to comment
Share on other sites

oh i thinks you can code all in 1 file php, php style should use post in selfExample:file: contact.php have "html and code php"<html><?php if ($_POST){ $myemail= $_POST['email']; $subject = "Mailing List"; $message = "E-mail: $email"; mail($myemail, $subject, $message); exit();}?><div id="mailinglist"> <form action="" method="post" target="_blank" name="frm_post"> <b>Stay Updated, Sign Up! <br />E-mail:</b> <input type="text" name="email" size="13" value="" /> <input type="submit" value="Submit" /> </form> </div></html>

Link to comment
Share on other sites

I just want to thank you guys for the help and i will test the methods you have posted when i get home, I also want to note and apologize because the form is working i just failed to notice that it was being sent to my spam folder! sorry i didnt notice that!Follow up question i have been reading a lot about the subject and i am curious how secure this method is? i was reading how dealing with php can leave you vularable to hackers and they get destroy your website. Am i safe or is there something i cando to prevent this.

Link to comment
Share on other sites

Am i safe or is there something i can do to prevent this.
you need to validate your inputs properly..validate $_POST['email] ..using http://php.net/function.preg_match..so that no one can exploit it.
Link to comment
Share on other sites

you need to validate your inputs properly..validate $_POST['email] ..using http://php.net/function.preg_match..so that no one can exploit it.
I apologize i am not to firmilliar with php, obviously, and i dont know exactly what you mean. But i will shovel through some tutorials to try and put it all together.
Link to comment
Share on other sites

it's the same for any sort of UI where you are taking inputs from a user. You have to validate the inputs to make sure they are of the correct 'type'. i.e. an email should include the @ symbol and some sort of domain extension. A name input should only consist of letters, etc. Regex is an object that can be used to search and look for patterns in strings for such these kinds of things, albeit they have a bit of a learning curve to them.and also to be making sure someone is not submitting malicious code to your form/database/script, etc.

Link to comment
Share on other sites

it's the same for any sort of UI where you are taking inputs from a user. You have to validate the inputs to make sure they are of the correct 'type'. i.e. an email should include the @ symbol and some sort of domain extension. A name input should only consist of letters, etc. Regex is an object that can be used to search and look for patterns in strings for such these kinds of things, albeit they have a bit of a learning curve to them.and also to be making sure someone is not submitting malicious code to your form/database/script, etc.
Thanks for the detailed explaination, makes sense now.
Link to comment
Share on other sites

Ok i got it to open up in a new window, thanks but im really scratching my head on the

you need to validate your inputs properly..validate $_POST['email] ..using http://php.net/function.preg_match..so that no one can exploit it.

I just have no idea how to implement this in my php code. The more i read, the more confused i get. PHP seems less trial and error more you have to know what the heck your doing.

Link to comment
Share on other sites

Regular expressions have a lot of power behind them, but are consequently difficult to understand until you walk through the expression very systematically. If you are interested in learning about them, I'd highly recommend reading this section of the PHP manual. For now, here's what you need to know. preg_match() matches the specified text against the RegEx (regular expression). You can easily find countless regexes if you do a search for "email validation regex" or a similar query.

$match = preg_match('/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/', $email); arguments: regex, input text (respectively)if ($match) { //if the preg_match function returned true, then...   //...send email} else {   //return an error}

Link to comment
Share on other sites

http://www.regular-expressions.info/quickstart.htmlif you want to learn from the begining about regex it is also the good one i guess..brief and descriptive.you can find lot of sites about regex if you google it.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...