[Tutorial] Making your own newsletter/opt-in form

Discussion in 'PHP' started by fairuz.ismail, Feb 4, 2008.

  1. #1
    <?php
    $msg = "";
    $ok = true;
    
    if ($_POST["submitted"] == "yes") {
    	
    	//initialize vars
    	reset ($_POST);
    	while (list ($key, $val) = each ($_POST))
    	{
      		if ($val)
        	$$key = $val;
    	}
    	
    	// name validation
    	if($name == ""){
    		$msg .= "Please enter your name.<br/>";
            $ok = false;
    	}
    
        // email validation    	    
    	if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) {
        	$msg .= "<b>Invalid email.</b><br/>";
            $ok = false;
    	}
    		
    	// sending email
    	if($ok == true){
    	
            $emailAdmin = "youremail@domain.com";
            $headers = 'From: "yourservice name"<youremail@domain.com>' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
            $subject = "yourservice subject";
    
    	    //ini merupakan msg anda
            $message = "Name : ".$name."\n";
            $message .= "Date : ".$date."\n";
            $message .= "Email : ".$email."\n";
    
            mail ("$emailAdmin","$subject","$message","$headers");
    		$msg .= "Thank you. Email sent.<br/>";
    	}
    }
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <body>
    <form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post" name="loginform">
      <table border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td><?php echo $msg; ?></td>
        </tr>
        <tr>
          <td>Nama:</td>
          <td><input type="text" name="name" id="name"/></td>
        </tr>
        <tr>
          <td>Email:</td>
          <td><input type="text" name="email" id="email"/></td>
        </tr>
        <tr>
          <td>Tarikh:</td>
          <td><input type="text" disabled="disabled" name="date" id="date" value="<?php echo date("d/m/Y"); ?>"/></td>
        </tr>
        <tr>
          <td><input type="hidden" name="submitted" value="yes" /></td>
          <td><input type="submit" value="Submit" /></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    PHP:
    p;s/ this is only a simple script. so no w3c compability in it.
    p:s/ you can change this script to whatever you want...if you still have problems with this, you can PM me..
    p:s/ if you dont have time to do this, you can always hire me to do it for you. thanks.
     
    fairuz.ismail, Feb 4, 2008 IP
  2. Doskono

    Doskono Peon

    Messages:
    153
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How is this a tutorial? It's just showing your script... It's not really a newsletter neither... News letter is sending everyone emails, but your just sending the email of an admin...
     
    Doskono, Feb 5, 2008 IP