Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very simple subscribe form for under construction page

Tags:

ajax

php

email

I'm setting up a Magento website and before it goes live I want to set up a under construction page.

I'd like to have people who are interested to subscribe and we'll send them out a email when the shop goes live.

I tried out bunch of these bigger PHP mailing/newsletter systems, but they were way to complicated and time consuming to get into because I need to work on other things.

So I'd like to know is there a easy way to do it myself or is there a script just for this task I haven't found yet? I also searched through few tutorial sites for what I was looking for, but I couldn't find anything useful. I really just need the bare minimum for this.

Thank you in advance, hopefully this question fits to this site.

like image 504
Vasar Avatar asked Dec 04 '22 09:12

Vasar


1 Answers

use this in your page:

<!-- Subscription Form -->
<form action="form/form.php" method="post">
    <input name="email" class="email" type="text" placeholder="Enter your email address ...">
    <button type="submit" class="btn_email">Send</button>
</form>
<!-- End Subscription Form -->

and this for form.php:

<?php
$to = "[email protected]";
$from = "[email protected]";

$headers = "From: " . $from . "\r\n";

$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];


if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{ 
    if (mail($to, $subject, $body, $headers, "-f " . $from))
    {
        echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
    }
    else
    {
       echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';   
    }
}
else
{
   echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';   
}

the above script will only send you an email with the new subscription, but you can extend it to do database insertion, subscriber confirmation, etc. And also validate the data in the field where the subscriber enter the email.

like image 93
bogdA Avatar answered Jan 03 '23 14:01

bogdA