...

View Full Version : Simple newsletter subscription form



_and_why_
08-15-2012, 02:08 PM
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:

<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

Len Whistler
08-15-2012, 08:35 PM
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

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>



----



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum