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
It wont stop spammers and it's not validated as an email address
This next version has very the basic validation of [email][email protected][/email]thing 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. [code=php]<? if(@$_POST['email_address']!=''){ if(preg_match("/^[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+$/",$_POST['email_address'])){ $to='[email protected]'; $subject='email entered'; $message='This email was entered '.$_POST['email_address']; mail($to,$subject,$message); $_POST['email_address']=''; }else{ echo "email format incorrect.<br />"; } }
edit: change [email][email protected][/email] 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.
@SyCoApr 16.2008 — #lol, [email][email protected][/email]thing 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 ?