Page 4 of 14 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 137

Thread: javascript? php? simple mailing list database?

  1. #31
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You can try making the file. It should make it itself if you didn't.
    Did you change the filename?
    If you changed the directory, you MUSt create the directory first, but not the file.
    See if making it changes anything... if not... I'll think about it.

    Hmm... that code should work... my syntax might be off.


    Wow... something is off with that .phps file. Can you make it .txt instead? I think its trying to display as a webpage, not show the source.
    Actually... hitting view source shows the php too... so... whatever, that works.

    One idea... find this at the end of that alert code:
    <?php }?>>
    and change to:
    <?php } ?>>
    or
    <?php } ?> >

    See if that helps... might just be a spaces thing.


    And... yeah, you can make it from the address.


    But... don't you just want it to be from the apache thing? Doesn't matter.... the file will hold the emails.... the apache thing will make it clear its auto-generated.

    Change the mail command to:
    mail("tom@curiousclothing.com", "Newsletter Nofication", "This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.", "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());

    That'll set the from to the email, the reply-to address to the email and the mail sender thing to php+version. (the last just being recommended by a tutorial I saw)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #32
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    great that now works! still no luck with the alert though: http://www.curiousclothing.com/index.txt, also do you think i should have some kind of javascript so people actually have to type a legit email with the @ symbol? Have you seen this done?

  3. #33
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    And the file still isn't showing up... great.
    Try switching it to "emails.txt", maybe.

    Yeah... I've got a script like that... did it for another page I wrote.

    PHP Code:
    $at strpos($email"@");
    $dot strpos($email"."$at+2);
    $atnum substr_count($email"@");
    if (
    $at == false or $dot == false or $dot == strlen($email) or $atnum 1)
        { 
    $bad email "The email address you entered is not valid. Please go back and try again.<br>"; } 
    You can put that after if ($email = stripslashes($_POST['email'])) {


    Then replace "<?php if ($message != "") { echo $message; }" with:
    <?php echo $bademail;
    if ($message != "") { echo $message; }


    **I'm not sure this is the best way.. it'll display that above the form.
    you could program it to do an alert or something too.
    what do you think?



    Also, fix this: $message = $message = "Your email was removed from the mailing list.";
    Take out one of the $message =.



    To fix the alert, I put "messages" instead of "message". Fix here:
    <body<?php if ($messages == "") { ?>
    Change to: <body<?php if ($message == "") { ?>
    sorry 'bout that... typing too fast, I guess.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #34
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Oh.... hmm...
    Use this:
    'cause you'll need to NOT add to the list if it's invalid. right.

    PHP Code:
    <?php
    if ($email stripslashes($_POST['email'])) {
    $filename "emails.phplist";
    $at strpos($email"@");
    $dot strpos($email"."$at+2);
    $atnum substr_count($email"@");
    if (
    $at == false or $dot == false or $dot == strlen($email) or $atnum 1)
        { 
    $bad email "The email address you entered is not valid. Please go back and try again.<br>"; } 
    else {
        
    $filecontents = @file_get_contents($filename);
        if (
    $_POST['choice'] == "join") {
            if (
    strpos($filecontents$email) != "") break; 
            if (
    strlen($filecontents) > 0$comma ", ";
            
    $add $comma.$email;
            
    $emails $filecontents.$add;
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$emails);
            @
    fclose($file);
            
    $message "Your email was added to the mailing list.";
        }
        elseif (
    $_POST['choice'] == "leave") {
            
    $edited str_replace($email,"",$filecontents);
            
    $file = @fopen($filename"w+");
            @
    fwrite($file$edited);
            @
    fclose($file);
            
    $message "Your email was removed from the mailing list.";
            }
        
    mail("tom@curiousclothing.com""Newsletter Nofication""This message has been automatically generated to inform you that $email has chosen to $choice the newsletter.""From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/".phpversion());
        }
    }
    ?>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #35
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    has an error now something to do with line 8 I think : http://www.curiousclothing.com/index.txt, I have this Javascript which I edited for another form... But not sure if adding it is different in php
    Code:
    <script language="JavaScript">
    <!--
    
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("email");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("Email");
    	// dialog message
    	var alertMsg = "Please complete the following fields:\n";
    	
    	var l_Msg = alertMsg.length;
    	
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    			}
    			if (obj.type == undefined){
    				var blnchecked = false;
    				for (var j = 0; j < obj.length; j++){
    					if (obj[j].checked){
    						blnchecked = true;
    					}
    				}
    				if (!blnchecked){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
    		}
    	}
    
    	if (alertMsg.length == l_Msg){
    		return true;
    	}else{
    		alert(alertMsg);
    		return false;
    	}
    }
    // -->
    </script>

  6. #36
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ignore that script it sux... doesn't check the @

  7. #37
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Wow, heh.

    Change: $bad email =
    to: $bademail =

    I'm out of it today. variables in php must be only one word. hehe.


    that php will verify the email. what is the js supposed to do?
    sorry, JS isn't my language.

    Generally, though, the php is totally separate from the js.
    Just do the js like normal.
    the only problem might arise if:
    1. the php showed the "added" message, not the form
    and
    2. the javascript is supposed to do something to the form.
    if this becomes an issue, a php if statement could hide the javascript if it hides the form.



    EDIT: "ignore that script"... ha, ok. easier, anyway.
    but the php will do that
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #38
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Have a good email checking script... Although can't seem to implememt it any ideas?
    Code:
    function isEmail(str) {
      // are regular expressions supported?
      var supported = 0;
      if (window.RegExp) {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
      }
      if (!supported) 
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
      var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
      var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
      return (!r1.test(str) && r2.test(str));
    }

  9. #39
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Just use the php. It's more secure, anyway.

    If that doesn't work, we can figure out what next.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #40
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    agreed... it just takes reloads the page... but doesn't give you any text warning? also uploaded the emails.txt file but doesn't seem to write anything to it...

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
  •