biomike1000
04-16-2008, 08:28 AM
I would like to make it possible for visitors to insert their email address in a box on my front page. once submitted their details get sent to the webmaster. any ideas
Thanks
Michael
Thanks
Michael
|
Click to See Complete Forum and Search --> : email routine for mailing list biomike1000 04-16-2008, 08:28 AM I would like to make it possible for visitors to insert their email address in a box on my front page. once submitted their details get sent to the webmaster. any ideas Thanks Michael SyCo 04-16-2008, 05:59 PM In it's absolute simplest form this would be copied to the page. <? if(@$_POST['email_address']!=''){ $to='webmaster@domain.com'; $subject='email entered'; $message='This email was entered '.$_POST['email_address']; mail($to,$subject,$message); } ?> <form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>"> <input type="text" name="email_address"> <input type="submit" value="Enter"> </form> It wont stop spammers and it's not validated as an email address This next version has very the basic validation of something@something.something which will let every valid email address through, check for basic formating but will not check beyond that. I usually find it's enough as the error most people make is forgetting to add the @ or the .com If they can't type their own email, who can help them? This version still will not stop spammers but thats another questions and I don't want to confuse you with a ton of anti spam stuff. This work for now. If you get spam put it in a onclick opened window, thats the easiest way to stop spam. <? if(@$_POST['email_address']!=''){ if(preg_match("/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/",$_POST['email_address'])){ $to='webmaster@domain.com'; $subject='email entered'; $message='This email was entered '.$_POST['email_address']; mail($to,$subject,$message); $_POST['email_address']=''; }else{ echo "email format incorrect.<br />"; } } ?> <form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>" style="display:inline;"> <input type="text" name="email_address" value="<?=@$_POST['email_address']?>"> <input type="submit" value="Enter"> </form> edit: change webmaster@domain.com to the domain you want to receive the emails. Most people would store the emails in a database you can send your email to everyone automatically. As your mailing list grows (with your PHP skills) investigate ways of using MySQL and PHP to set up a newsletter and mailing list. There's loads of tutorials on the web. SyCo 04-16-2008, 06:01 PM lol, something@something.something was automatically flagged as an email address and replaced with mailto tags. Only difference is the .some is limited to 4 characters. Looks like I'm not the only one validating using the very basics :) webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |