Jump to content

Mailing list problem!


hiimhenryyy

Recommended Posts

Hello,

 

I'm setting up a site for a clothing company and I'm having trouble with a mailing list snippet I got from a PHP site. Everything works fine until you click Join Now! When do you do this, everything beneath it is hidden for some odd reason. In my case, the footer.

 

Here is the link to the test site (You'll find it under "Get The Dirt" under the right section:

http://lookseewatch.com/test/ss/index.php

 

and here is the code I'm using.

 

<?
/*
Email list script
by phptutorial.info
*/

// to avoid showning errors (change to 1 to show them). For security
error_reporting(0);

// if info is posted, show the form and die
// the form is in the bottom of the page
if (!$_POST){print_form();die();}

// when info is posted you will be here
?>

<?

// GET EMAIL
        $email=$_POST["email"];
        // To avoid problems, only lower case is used
        $email=strtolower($email);
        // Check whether email is correct by using a function
        //  function requires the email address and the error message
        check_email ($email, "Oops! Email is not valid.");


// GET VALUE FOR action : subc (subscribe) or unsubc (unsubscribe)
$action=$_POST["action"];

// this is the file with the info (emails)
//    When using the link in the top to download the complete script, a new name for this file
//    will be generated (p.e.: emaillist-2ax1fd34rfs.txt), so users will be unable to find it
$file = "mailing_list_h5E2n3_45r_56Y.txt";

// lets try to get the content of the file
if (file_exists($file)){
        // If the file is already in the server, its content is pasted to variable $file_content
        $file_content=file_get_contents($file);
}else{
        // If the file does not exists, lets try to create it
        //   In case file can not be created (probably due to problems with directory permissions),
        //   the users is informed (the first user will be the webmaster, who must solve the problem).
        $cf = fopen($file, "w") or die("Error: file does not exits, and it can not be create.<BR>Please check permissions in the directory or create a file with coresponding name.");
        fputs($cf, "Mailing list subscribers\n");
        fclose($cf);
}

// IF REQUEST HAS BEEN TO SUBSCRIBE FROM MAILING LIST, ADD EMAIL TO THE FILE
if ($action=="subc"){
        // check whether the email is already registered
        if(strpos($file_content,"<$email>")>0){die("Oops! Your email is already subscribed to this mailing list.");}
        // write the email to the list (append it to the file)
        $cf = fopen($file, "a");
        fputs($cf, "\n<$email>");       // new email is written to the file in a new line
        fclose($cf);
        // notify subscription
        print "Thank you for subscribing to the Seed & Stem Newsletter.";
}
// IF REQUEST HAS BEEN TO UNSUBSCRIBE FROM MAILING LIST, REMOVE EMAIL FROM THE FILE
if ($action=="unsubc"){
        // if email is not in the list, display error
        if(strpos($file_content,"<$email>")==0){die("Sorry, your email is not subscribed to this mailing list.");}
        // remove email from the content of the file
        $file_content=preg_replace ("/\n<$email>/","",$file_content);
        // print the new content to the file
        $cf = fopen($file, "w");
        fputs($cf, $file_content);
        fclose($cf);
        // notify unsubscription
        print "Your email has been removed from our mailing list. ";
}

?>


<?
// THIS FUNCTION WILL CHECK WHETHER AN EMAIL IS CORRECT OR NOT
//      FIRST, BASIC ARCHITECTURE IS CHECKED
//      THEM, EXISTANCE OF THE EMAIL SERVER IS CHECKED
// If email is not correct, the error message is shown and page dies
function check_email ($email, $message){
        // check if email exists
           if ($email==""){die($message);}
        // check whether email is correct (basic checking)
           $test1=strpos($email, "@");                                     //value must be >1
           $test2=strpos(substr($email,strpos($email,"@")), ".");          //value must be >1
           $test3=strlen($email);                                          //value must be >6
           $test4=substr_count ($email,"@");                               //value must be 1
           if ($test1<2 or $test2<2 or $test3<7 or $test4!=1){die($message);}
        // check whether email is correct (advance checking)
           // extracts whatever is after "@" to variable $email_server
           $email_server=substr($email,strpos($email, "@")+1);
           // Check DNS records (0 => the server exists; 1=> the server does not exist)
           if (checkdnsrr($email_server)!=1){die ($message);}
}

// THIS FUNCTION WILL SHOW THE FORM
// MODIFY IT AS REQUIRED
function print_form(){
?>
        <form action="<? $PHP_SELF; ?>" method="post">
          <table>
             <tr>
             <td>
			<input name="email" size="30" type="text">
                <input name="action" value="subc" checked="checked" type="hidden">
                <input value="Join Now!" type="submit">
              </td>
              </tr>
          </table>
        </form>


 

Hopefully someone can guide me in the right direction. I'm not very good with PHP.

 

Thank you,

Henry

Link to comment
Share on other sites

everything beneath it is getting hidden because the check_email function is using die() when an error occurs, which terminates the script.

you can change die to echo, depending on how you've got it all set up.

also you'll want to check that the emails being passed to the check_mail function correctly, i tried typing in a legit email and it came back saying "Oops! Email is not valid."

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.