Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-15-2012, 02:08 PM   PM User | #1
_and_why_
New to the CF scene

 
Join Date: Aug 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
_and_why_ is an unknown quantity at this point
Simple newsletter subscription form

I've been scouring the web for a tutorial or code that will enable my "subscribe to my newsletter" to send an email to a certain account, but I am in the very beginnings of web dev, so have no idea on PHP or whatever is needed. I litterally only know the basics of HTML.

So, here is my form's code:
Code:
<form action="mail.php" method="POST" class="newsletter">
	<h3>Subscribe to our Newsletter</h3><br>
	<p>Be the first to hear about our new treatments, special offers and events</p></br>
	<input type="text" name="email" placeholder="Enter email address" size=40 class="input"/>
	<p><input type="submit" value="Subscribe" class="button" /></p>
</form>
I do not currently have a mail.php file, but from what I have read I need that? What code would go in that file?

Also, if I'm using php, would I have to change the file type to .php, instead of .html?

Please help.

Thanks,

Andy
_and_why_ is offline   Reply With Quote
Old 08-15-2012, 08:35 PM   PM User | #2
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
Quote:
Originally Posted by _and_why_ View Post
Also, if I'm using php, would I have to change the file type to .php, instead of .html?

Yes ...... And to view the php file you must have php running for that directory. You can put everything into one php file, I would also consider sending sending an email to yourself notifying you when ever someone has subscribed.


Untested, there might be syntax errors.

subscribe.php
PHP Code:
<?php

if (isset($_POST['email'])) {

$to "$_POST['email']";
$subject "";
$message "";
mail($to$subject$message);

$your_email "your email";
$subject_to_you "someone subscribed to your news letter";
$message_to_you "";
mail($your_email$subject_to_you$message_to_you);

}
?>
<html>
<body>
<form action="mail.php" method="post" class="newsletter" action="<?php echo $PHP_SELF;?>">
<h3>Subscribe to our Newsletter</h3><br>
<p>Be the first to hear about our new treatments, special offers and events</p></br>
<input type="text" name="email" placeholder="Enter email address" size=40 class="input"/>
<p><input type="submit" value="Subscribe" class="button" /></p>
</form>
</body>
</html>


----
__________________
Leonard Whistler

Last edited by Len Whistler; 08-15-2012 at 08:52 PM..
Len Whistler is offline   Reply With Quote
Users who have thanked Len Whistler for this post:
_and_why_ (08-17-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04 PM.


Advertisement
Log in to turn off these ads.