/    Sign up×
Community /Pin to ProfileBookmark

email routine for mailing list

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

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SyCoApr 16.2008 — In it's absolute simplest form this would be copied to the page.

[code=php]<?
if(@$_POST['email_address']!=''){
$to='[email protected]';
$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>[/code]


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 />";
}
}

?>
<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>[/code]




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.
Copy linkTweet thisAlerts:
@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 ?
×

Success!

Help @biomike1000 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...