Results 1 to 8 of 8

Thread: mail script newsletter

  1. #1
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default mail script newsletter

    Hey all,
    I have this php script that I use for my contact form, and it works perfectly.
    Now I'd like to have a script subscribing to a newsletter, that just sends me the email adres filled in the area, also checking if it is a valid mailadres.

    Here's the mailform code I have, just for information:

    Code:
    <?php
    if ($_POST["action"] == "send"){
    if ($_POST[naam] != " je naam" and $_POST[naam] != "" and $_POST[email] != " je e-mail adres" and $_POST[email] != "" and $_POST[bericht] != "") { 
    mail ("info@domain.com", "via site", 
    "
    Naam: ".$_POST['naam']."
    E-mail: ".$_POST['email']."
    Bericht: ".$_POST['bericht']."
    ",
    "From: ".$_POST['naam']." <".$_POST['email'].">");
    $subject = "your message to"; 
    $msg = "
    Dear $_POST[naam],
    Thanks for your message. Will get back to you shortly.
    This was your message:
    $_POST[bericht] 
    ";  
    mail($_POST[email], $subject, $msg); 
    echo 'thanks for your feedback !';
    }
    else{
    echo 'please fill in all fields';
    }
    }
    ?>
    Can anyone help me out, please ?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Do you just want something emailing you the email they put in, or a whole system that inserts the email in a db, then a little admin form for you where you can send everybody an email, or what. xD
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    Just something that mails me the adress that the visitor put in the field, nothing more. I don't expect many subscribers, so wouldn't bother for now

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Here it is:

    PHP Code:
    <?php
    include('includes/functions.php');
    $myemail "name@mail.com"// Edit this with your email address
    $mysubj "New User"// Set the subject of mail that you will receive from users
    if ($_POST["action"] == "send"){
    if (
    $_POST[naam] != " je naam" and $_POST[naam] != "" and $_POST[email] != " je e-mail adres" and $_POST[email] != "" and $_POST[bericht] != "") { 
    mail ("info@domain.com""via site"
    "
    Naam: "
    .$_POST['naam']."
    E-mail: "
    .$_POST['email']."
    Bericht: "
    .$_POST['bericht']."
    "
    ,
    "From: ".$_POST['naam']." <".$_POST['email'].">");
    $subject "your message to"
    $msg "
    Dear 
    $_POST[naam],
    Thanks for your message. Will get back to you shortly.
    This was your message:
    $_POST[bericht] 
    "
    ;
    if(
    checkEmail($_POST['email']))
    {
    mail($_POST[email], $subject$msg);
    mail($myemail$mysubj$_POST['email']); // Sends the mail to you
    }
    else
    die(
    'Invalid Email');

    echo 
    'thanks for your feedback !';
    }
    else{
    echo 
    'please fill in all fields';
    }
    }
    ?>
    checkEmail function:

    PHP Code:
    function validEmail($email)
    {
    if(!
    preg_match('/^[^0-9][A-z0-9_-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$/',$email))
    return 
    false;

    else
    return 
    true;

    Put the function in an includes file somewhere, like "includes/functions.php". If for whatever reason you don't / can't do this then just copy the function straight into the top of the page.

    Found the checkMail function through google but it seems to work well enough. It doesn't check for DNS records but I mean as you said your not expecting 1000s of subscribers and people potentially makings bots to spam your site, for what you want it should be sufficient

    You could always have the $mysubj variable dynamic, but I don't know how you want it done, so I've just left it as it is.

    Good Luck

  5. #5
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    No, no no ! The code you gave has "name", "email","message" etc !
    I just need a form that sends me the email that is written in the input box, nothing more (and maybe a confirmation mail to the sender).
    So there is no "name" and "message" !

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Oh so their email address is the title of the email itself? I see... in that case...

    PHP Code:
    <?php
    include('includes/functions.php');
    $myemail "name@mail.com"// Edit this with your email address
    if ($_POST["action"] == "send"){
    if (
    $_POST[naam] != " je naam" and $_POST[naam] != "" and $_POST[email] != " je e-mail adres" and $_POST[email] != "" and $_POST[bericht] != "") { 
    mail ("info@domain.com""via site"
    "
    Naam: "
    .$_POST['naam']."
    E-mail: "
    .$_POST['email']."
    Bericht: "
    .$_POST['bericht']."
    "
    ,
    "From: ".$_POST['naam']." <".$_POST['email'].">");
    $subject "your message to"
    $msg "
    Dear 
    $_POST[naam],
    Thanks for your message. Will get back to you shortly.
    This was your message:
    $_POST[bericht] 
    "
    ;
    if(
    checkEmail($_POST['email']))
    {
    mail($_POST[email], $subject$msg);
    mail($myemail$_POST['email'],''); // Sends just the email to you with a blank message
    }
    else
    die(
    'Invalid Email');

    echo 
    'thanks for your feedback !';
    }
    else{
    echo 
    'please fill in all fields';
    }
    }
    ?>
    Hope this is what you're looking, I may be missing something but I think this is what you mean

  7. #7
    Join Date
    Jul 2006
    Location
    Antwerp, Belgium (Europe)
    Posts
    927
    Thanks
    121
    Thanked 2 Times in 2 Posts

    Default

    The codes below refer to "name" or "message", which there isn't in the form !
    Maybe you could start from scratch, and not look at the code I attached in my first post, please.
    This is all I need: how to send a filled in email adress (to subscribe to a newsletter), and send a confirmation mail to the filled in adress.

    Code:
    if ($_POST[naam] != " je naam" and $_POST[naam] != "" and $_POST[email] != " je e-mail adres" and $_POST[email] != "" and $_POST[bericht] != "") {
    Code:
    Naam: ".$_POST['naam']."
    E-mail: ".$_POST['email']."
    Bericht: ".$_POST['bericht']."
    Code:
    "From: ".$_POST['naam']." <".$_POST['email'].">");
    $subject = "your message to"; 
    $msg = "
    Dear $_POST[naam],
    Thanks for your message. Will get back to you shortly.
    This was your message:
    $_POST[bericht] 
    ";

  8. #8
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Oh I see, I was going on the assumption that you wanted to keep the other code , right... So there's just an input box with the email so:

    PHP Code:
    <?php
    function checkEmail($email)
    {
    if(!
    preg_match('/^[^0-9][A-z0-9_-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$/',$email))
    return 
    false;

    else
    return 
    true;
    }

    $subj "Subscription Notice"// Subject of the email the user receives
    $msg "Thanks for subscribing to my newsletter, you will be added to the list soon"// Enter message of the email here the user receives
    $mymail 'myemail@email.com'// Change to your email

    if (isset($_POST['email']) && !$_POST['email'] == ''// Check fields not empty and have been submitted
    {
     if(
    checkEmail($_POST['email'])) // Make sure email is valid
      
    {
       
    mail($_POST['email'], $subj$msg); // Send mail to user
       
    mail($mymail$_POST['email'], ''); // Send mail to you
       
       
    die('Email added, please check your inbox for confirmation');
      }
     else
     die(
    'Invalid Email');
        
    }
    else
    die(
    'Please fill in the email field');

    ?>

  9. The Following User Says Thank You to Schmoopy For This Useful Post:

    chechu (03-31-2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •