SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    626
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question E-mail Box Submission Script

    Hello all,

    This is a question about a PHP script for collecting e-mails in my submission box at my website that I'd like help in writing myself in order to do the following:

    1. Check the submission to see if it is, in fact, at a web address with an @ in the submission.
    If it contains an e-mail address, send a test e-mail and see if the e-mail address is valid.
    If it sends successfully, do the following:
    Display screen with "Check here if you would like to be added to..."
    When that is selected and the user clicks okay, do this:
    Send an e-mail to 2 e-mail addresses for me
    Write user to mySQL database on server.


    To start, this is what is there for the form on the home page:
    Code:
    <form id="emailbox" name="form1" method="post" action="email.php">
            <div>
              <input type="text" name="go" id="go" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)"/>
              <input type="submit" value="Join" />
            </div>
          </form>

    I was having trouble finding a good predefined method in the php.net directories for strings to test if there is a .com, .net, .biz, .org, .info, etc. & if there is an @ in the submission- do you know of one?

    I would also like to limit the number of characters in a valid submission. Let me liberal, say, a maximum of 60 characters. Would that be done in JavaScript or something besides PHP?

    I would be using a global variable, $email, which would be initialized through
    Code:
     $_POST["go"]
    , as you can see in the form markup. Then I can make a function, isItAValidEmail(), for the submission testing, then a second function for test e-mail and e-mail list joining acceptance is displayed using the echo(**some HTML & their styles**) function.


    Thanks for the suggestions.
    I'd like to do this on my own and build some experience with PHP instead of just use some service.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by etidd View Post
    1. Check the submission to see if it is, in fact, at a web address with an @ in the submission
    a preg_match on the string. Though as we noted in a recent thread, emails are a bit tricky to detect correctly.
    If it contains an e-mail address, send a test e-mail and see if the e-mail address is valid.
    No way to test for validity. See next point.
    If it sends successfully, do the following:
    Sending successfully and actually having a mailbox on the other end are two entirely seperate conditions, and you cant really test for the second one (at least, not during the course of a page-load)
    Display screen with "Check here if you would like to be added to..."
    Simple enough..
    When that is selected and the user clicks okay, do this:
    Send an e-mail to 2 e-mail addresses for me
    Write user to mySQL database on server.
    Also simple enough, as you've already sent one email, you should be able to send 2 more, and a database add is simple enough.

    To start, this is what is there for the form on the home page:
    Code:
    <form id="emailbox" name="form1" method="post" action="email.php">
            <div>
              <input type="text" name="go" id="go" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)"/>
              <input type="submit" value="Join" />
            </div>
          </form>

    I was having trouble finding a good predefined method in the php.net directories for strings to test if there is a .com, .net, .biz, .org, .info, etc. & if there is an @ in the submission- do you know of one?
    See above linked thread. We give a couple of suggestions for regex in terms of emails.
    I would also like to limit the number of characters in a valid submission. Let me liberal, say, a maximum of 60 characters. Would that be done in JavaScript or something besides PHP?
    Both. Javascript cant be relied on to be active on someone's browser, so PHP should do the check as well.
    I would be using a global variable, $email, which would be initialized through
    Code:
     $_POST["go"]
    , as you can see in the form markup. Then I can make a function, isItAValidEmail(), for the submission testing, then a second function for test e-mail and e-mail list joining acceptance is displayed using the echo(**some HTML & their styles**) function.
    the words 'global' and 'variable' should be avoided together whenever possible. Pass the variable around to your functions.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    626
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Red face Moving Forward with Crafting My Script

    Yes, this was a very elaborate response. Thank you!

    After reviewing your post's info in detail, delving into PHP 6 & MySQL 5 by Larry Ullman (and installing a testing server on this machine using XAMPP), I have some questions.

    For the HTML markup, this is what I've compiled there:
    Code:
    <form id="emailbox" name="form1" method="post" action="Scripts/email.php">
            <div>
              <input type="text" name="go" id="go" value="your e-mail" onclick="input_focus(this)"  onblur="input_reset(this)"/>
              <input type="submit" value="Join" onclick="showWindowAndValidate()" />
            </div>
          </form>
    This is the current draft of PHP I'm drawing up:
    Code:
    <?php
    	  //This is the scripting section for the e-mail collection box.
    	$email = " ";
    	
    	function showWindowAndValidate()
    	{
    		echo'<div id="activeemailbox"><input type="checkbox" value="Yes\, I would like to join the mailing list."></p>';	
    	}
    	
    	if (isset($_POST["go"])
    		
    		$email = $_POST["go"];
    		if (isItAValidEmail())
    			//send me an e-mail and a bunch of other crazy stuff
    	else
    		echo'<div id="activeemailbox"><p id="error">You didn\'t enter an email, silly!</p><input type="submit" value="Go Back" onclick="invalidEntry()"></div>';
    	
    	/*test the e-mail address submission for valid entry */
    	function isItAValidEmail()
    	{
    		$lastChars = " ";
    		$lastChar = $
    		//preg match on $email
    	}
    	
    	function invalidEntry()
    	{
    		//go back to the main home page screen
    	}
    	//end e-mail box scripting section
    ?>
    Note that this draft contains another objective, giving an error screen that will turn the user back to the home page when the e-mail has been declared invalid by my functions. I'm lost there.

    I'd also like to make my home page go into a dark gray overlay, making it look inactive, while the user is interacting with the e-mail list part.
    (That may be a CSS question)

    I'd also like to find out why I'm getting a syntax error around the only conditional statement in the script so far.
    Parse error: syntax error, unexpected '$email' (T_VARIABLE) in C:\xampp\htdocs\index.php on line 392


Tags for this Thread

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
  •