Status
Not open for further replies.

Gavin

New Member
I am planning to start a monthly newsletter for one of my sites so I am needing some code.

Can anyone recommend any code that allows visitors to submit their email address. Also, if they do submit their email address is their anything that can be done to keep them on the same page they were reading?

I am using include files with HTML.
 

daviddoran

New Member
Hi Cormac,
Are you planning to manually CC a list of people who subscribed or would you like to have some software automatically do it?

Allowing sign-up via a form is quite easy, as is storing the email-address, if you would like a web application that allows you to format your email and send it then I'm sure there's one out there.

As for keeping them on the same page, there are two options:
- Have the form dynamically submit via AJAX (no page reload).
- Or have the form submit to a processing page and then back to the page they were on.
 

Gavin

New Member
I would just want their email address sent to my own so I can add it to an excel sheet for later.

I have always been meaning to learn Ajax, I suppose this project would probably be the best to start with.
 

daviddoran

New Member
I that case then what you want is: (I am assuming you are using PHP)
- SAJAX (for implementing AJAX) - modernmethod.com/sajax/
- set the onsubmit value of your form to the AJAX call.
- Have your backend receive the email and use PHP mail function to send to you.

Basically.
 

louie

New Member
using Ajax just for a simple matter like that is too much work.
If you use include files and have the form displayed on every page, leave the action field empty, this way the form will submit to the same page you are on, or grab the page name and query string.

Inside the form ad a hidden field named "email_subscribe" or something unique with the value="1".

Inside the include page, before the form add your code to verify the email, and if no errors found, either added to a database or email it to yourself, then shown a nice "Thank you" message.
 

kae

New Member
louie, got to admit, though, that AJAX, even for tiny thins, really adds a little "sparkle" to a website.

My own opinion on this is; the OP appears to me to not be too comfortable with programming (or he would have mentioned a language, etc), so a non-programming solution would probably be right for him.

Probably something as simple as this would do the trick:
<a href="mailto:subscribe@blah.blah.com?subject=subscribe_me">Click Here to subscribe</a>

Yes, the "?subject=" bit is non-standards-based, but (and this is the important bit) it works.
 

daviddoran

New Member
That's all well and good but I don't know any non-technical person who has their email software setup.
It's a five minute job in PHP anyway.
 

7aken

New Member
hi cormac,

willing to learn eh? have a look at the below code, its a 'form' which will sit on your webpage first, then the php file that makes the magic! its very straighforward but its a start, you can just copy and paste this code if you want but i suggest you try to understand whats happening. i'll try to comment it as much as i can to help you understand

first, this code is the form which you place wherever you want on your webpage

HTML:
<form method="post" action="mailer.php"><br /> <!-- note the name of the php file -->
<input type="text" name="name" size="20"> <br />
Your Name<br />
<input type="text" name="email" size="20"><br />
 Email Address<br />
<input type="submit" name="submit" value="submit"></form>

next is your php file which in this case we called mailer.php

PHP:
<?php 
if(isset($_POST['submit'])) { //checks to sit if submit button has been used
$to = "you@you.com";    //enter the email address that you want info sent to here
$subject = "newsletter signup"; //email subject 
$name_field = $_POST['name']; //retrieves users name
$email_field = $_POST['email']; // retrieves users email address

$body = "From: $name_field\n E-Mail: $email_field\n "; 
  
echo "You have signed up for our Newsletter!"; 
mail($to, $subject, $body);
} else { 
echo "There appears to be an error. please try again ";
} 
?>

and there you have it, its very basic and doesnt redirect users back to the same page but you can figure that bit out yourself!!
 

paul

Ninja
have a look at this
Mr. D's Free PHP Contact Us Script

I've found it to be the best at what it does, in includes a basic image CAPTHCA and checks the referring source and other fancy bits. I had to do this when I got some funny mail program trying to pass weird strings to my less advanced script.
 
Status
Not open for further replies.
Top