Sending user-requested information : mail « Utility Function « PHP






Sending user-requested information

 
//File: index.php
<html>
<head>
<title></title>
</head>
<body>
<?
$form = "<form action=\"index.php\" method=\"post\">
<input type=\"hidden\" name=\"seenform\" value=\"y\">
Your Email:<br>
<input type=\"text\" name=\"email\" value=\"\"><br>
<input type=\"checkbox\" name=\"information[team]\" value=\"y\">Development
Team<br>
<input type=\"checkbox\" name=\"information[events]\" value=\"y\">Upcoming
Events<br>
<input type=\"submit\" value=\"send\">
</form>";
if ($seenform != "y") :
     print "$form";
else :
     $headers = "From: d@yoursite.com";
     while ( list($key, $val) = each ($information) ) :
          if ($val == "y") :
               $filename = "$key.txt";
               $subject = "Requested $key information";
               $fd = fopen ($filename, "r");
               $contents = fread ($fd, filesize ($filename));
               mail($email, $subject, $contents, $headers) or die("Can't send email!");
               fclose($fd);
          endif;
     endwhile;
     print sizeof($information)." newsletters have been sent to $email!";
endif;
?>
</body>
</html>
  
  








Related examples in the same category

1.Add both name and address values into the email address
2.mail() function mails information to a given recipient.
3.mail-javascript.php
4.Using mail() to redirect user information
5.Encrypting and Sending Secure Emails Using S/MIME
6.send-email-multiple-recipients-2.php
7.send-email-with-headers.php
8.send-mail-multiple-recipients.php
9.send-plaintext-email.php
10.Sends a HTML mail from a given email address:
11.Sending Internet Mail
12.Sending Mail
13.Sending a message with mail()