You are here: Re: Output to another window « PHP Programming Language « IT news, forums, messages
Re: Output to another window

Posted by Jim Michaels on 02/12/06 04:55

most people have popup blockers which will cancel the new window. google
and yahoo toolbar will do this.

"astromac" <obearsstate@gmail.com> wrote in message
news:1138817935.934711.314490@o13g2000cwo.googlegroups.com...
> Fair enough. I work at a church and my boss wanted me to write a
> script to send emails to the congregation and have the progress of the
> emailing show up in another window. As far as why bother, it's what I
> was asked to do. As far as why not output the results in the same
> window, I didn't like how it printed the output at the top of the form
> and kept pushing the form down. I'm a civil engineer by trade so I'm
> sure the code is stupidly written and inefficient so be kind (I'm new
> to PHP and javascript). BTW, you're not helping a spammer - this is
> for folks who attend our conferences every year and have requested an
> HTML brochure rather than a printed brochure.
>
> Anyway - here's the code in order to provide you with detail.
>
> <?php
> $email_from = isset($_POST['email_from']) ?
> htmlentities($_POST['email_from']) : '';
> $email_from_name = isset($_POST['email_from_name']) ?
> htmlentities($_POST['email_from_name']) : '';
> $email_subject = isset($_POST['email_subject']) ?
> htmlentities($_POST['email_subject']) : '';
> $email_delay = isset($_POST['email_delay']) ?
> htmlentities($_POST['email_delay']) : '';
> $errors['cant_open_message'] = "<script type=\"text/javascript\">alert
> (\"Can't Open Message File\");</script>";
> $errors['cant_open_address'] = "<script type=\"text/javascript\">alert
> (\"Can't Open Address File\");</script>";
>
> function showform ($_email_from, $_email_subject, $_address_file,
> $_message_file, $_email_delay, $_mime_type) {
> print<<<_HTML_
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html lang="en">
> <head>
> <meta http-equiv="content-type" content="text/html;
> charset=iso-8859-1">
> <title>Conference Email Form</title>
> <meta name="generator" content="BBEdit 8.2">
> <script type="text/javascript">
> var newListWindow;
> var newTextWindow;
> function makeListWindow() {
> if (!newListWindow || newListWindow.closed) {
> newListWindow = window.open("", "popList",
> "resizeable,scrollbars,height=400,width=400");
> //delay writing until window exists in IE/Windows
> setTimeout("writeListWindow()", 50);
> }
> else if (newListWindow.focus) {
> newListWindow.focus();
> }
> }
> function startListWindow() {
> var newContent = "<html><head><title>Successful
> Sends</title></head>";
> newContent += "<body><h1>Successful Sends</h1><br/>";
> newListWindow.document.write(newContent);
> }
> </script>
> <style type="text/css">
> body {
> color: #00008B;
> font-family: "Trebuchet MS", sans-serif;
> font-size: 1em;
> }
> h1 {
> color: #FFFFFF;
> background-color: #00008B;
> text-indent: 6px;
> }
> form {
> border: 1px dashed #00008B;
> padding: 3px 6px 3px 6px;
> background-color: #EAF6FF;
> }
> form p {
> clear: left;
> margin: 0;
> padding: 0;
> padding-top: 5px;
> }
> form p label{
> float: left;
> width: 30%;
> }
> input.txt {
> width: 250px;
> color: #00008B;
> background-color: #ADD8E6;
> border: 1px solid #00008B;
> font-weight: bold;
> }
> input.fil {
> color: #00008B;
> background-color: #ADD8E6;
> border: 1px solid #00008B;
> font-weight: bold;
> }
> input.del {
> width: 40px;
> color: #00008B;
> background-color: #ADD8E6;
> border: 1px solid #00008B;
> font-weight: bold;
> }
> input.btn {
> color: #00008B;
> background-color: #ADD8E6;
> border: 1px outset #00008B;
> font-weight: bold;
> }
> </style>
> </head>
> <body>
> <h1>Conference Email Form</h1>
> <form enctype="multipart/form-data" method="POST"
> action="$_SERVER[PHP_SELF]">
> <p>
> <label for="from">Email From Address:</label>
> <input type="text" id="from" name="email_from" value="$_email_from"
> class="txt">
> </p>
> <p>
> <label for="name">Email From Name:</label>
> <input type="text" id="name" name="email_from_name"
> value="$_email_from_name" class="txt">
> </p>
> <p>
> <label for="subject">Email Subject:</label>
> <input type="text" id="subject" name="email_subject"
> value="$_email_subject" class="txt">
> </p>
> <p>
> <label for="list">Address List:</label>
> <input type="file" size="32" id="list" name="address_file"
> class="fil">
> </p>
> <p>
> <label for="message">Mail Message:</label>
> <input type="file" size="32" id="message" name="message_file"
> class="fil">
> </p>
> <p>
> <label for="delay">Delay Between Email Sends:</label>
> <input type="text" id="delay" name="email_delay"
> value="$_email_delay" class="del"> minutes
> </p>
> <p>
> <label for="mime">Message Type:</label>
> <input type="radio" id="mime" name="mime_type" value="html"> HTML
> <input type="radio" id="mime" name="mime_type" value="text"> Plain
> Text
> </p>
> <br/>
> <br/>
> <p>
> Send Email<br/>
> <input type="submit" value="Process Now" name="submit" class="btn">
> &nbsp;&nbsp;
> <input type="hidden" name="submit_check" value="1">
> </p>
> </form>
> </body>
> </html>
> _HTML_;
> }
>
> function emailcheck ($_emailaddr) {
> # Trim out 'null' characters
> $_emailaddr = ereg_replace("\t","",$_emailaddr);
> $_emailaddr = ereg_replace("\r","",$_emailaddr);
> $_emailaddr = ereg_replace("\n","",$_emailaddr);
> $_emailaddr = ereg_replace(" ","",$_emailaddr);
>
> # Email addresses are not case sensitive
> $_emailaddr = strtolower($_emailaddr);
>
> # Must contain '@' and '.'
> if ((!ereg("@",$_emailaddr)) || (!ereg(".",$_emailaddr))) {
> $valid = "0";
> }
>
> # Must be at least 6 characters long (x@y.com or x@y.au)
> elseif (strlen($_emailaddr) < 6) {
> $valid = "0";
> }
>
> else {
> # Split on the @ sign
> $parts = split("@", $_emailaddr, 2);
>
> # First part is user
> $user = $parts[0];
>
> # Second part is domain
> $domain = $parts[1];
>
> # Domain must contain at least 1 dot.
> if (!ereg("\\.",$domain)) {
> $valid = "0";
> }
>
> # Must be a least 3 characters (z.com or z.au)
> elseif (strlen($domain) < 3) {
> $valid = "0";
> }
>
> # May not start with a dot
> elseif (ereg("^\\.",$domain)) {
> $valid = "0";
> }
>
> # May not have more than one dot in sequence
> elseif (ereg("\\.\\.",$domain)) {
> $valid = "0";
> }
>
> else {
> # User must be at least 1 character long
> if (strlen($user) < 1) {
> $valid = "0";
> }
>
> # User cannot contain a comma
> elseif (ereg("\\,", $user)) {
> $valid = "0";
> }
>
> else {
> # Split on the . character
> $parts = split("\\.", $domain);
>
> # There must be at least two parts to a domain (a sub domain would
> have 3 - a.b.com)
> if (count($parts) < 2) {
> $valid = "0";
> }
>
> else {
> # First part is domain name
> $name_at = count($parts) - 2;
> $name = $parts[$name_at];
>
> # Second part is domain extention
> $ext_at = count($parts) - 1;
> $ext = $parts[$ext_at];
> $first_name = substr($name, 0, 1);
>
> # Name must be at least one character
> if (strlen($name) < 1) {
> $valid = "0";
> }
>
> # Name cannot be more than 26 characters
> if (strlen($name) > 26) {
> $valid = "0";
> }
>
> # Extention must be 2 or 3 characters (.nu - .com)
> elseif ((strlen($ext) > 3) || (strlen($ext) < 2)) {
> $valid = "0";
> }
>
> # Domain can only contain the following characters
> elseif (strspn($name, "abcdefghijklmnopqrstuvwxyz0123456789-.") !=
> strlen($name)) {
> $valid = "0";
> }
>
> # Domain can only start with the following characters
> elseif (strspn($first_name, "abcdefghijklmnopqrstuvwxyz") < 1) {
> $valid = "0";
> }
>
> # Extension can only contain the follow characters
> elseif (strspn($ext, "abcdefghijklmnopqrstuvwxyz") !=
> strlen($ext)) {
> $valid = "0";
> }
> else {
> $valid = "1";
> }
> }
> }
> }
> }
> return $valid;
> }
>
> function sendmail ($_address_file, $_email_from, $_email_from_name,
> $_email_subject, $_email_message, $_mime_type) {
> $f = 0;
> print "<script
> type=\"text/javascript\">makeListWindow();startListWindow();</script>";
>
> foreach ($_address_file as $key => $value) {
> $pieces = explode(",", $value);
> foreach ($pieces as $piece_no => $piece_value) {
> if ($piece_no == 0) {
> $lastname[$key] = $piece_value;
> }
>
> if ($piece_no == 1) {
> $firstname[$key] = $piece_value;
> }
>
> if ($piece_no == 2) {
> $email[$key] = $piece_value;
> }
> }
> $fullname = $firstname[$key].' '.$lastname[$key];
> if ($fullname != ' ') {
> $to = '"'.$fullname.'" <'.$email[$key].'>';
> }
> else {
> $to = $email[$key];
> }
> if ($_email_from_name != '') {
> $from = '"'.$_email_from_name.'" <'.$_email_from.'>';
> }
> else {
> $from = $_email_from;
> }
>
> if ($_mime_type == "html") {
> $headers = "From: $from\r\n";
> $headers .= "MIME-Version: 1.0\r\n";
> $boundary = md5(uniqid(rand(), true));
> $headers .= "Content-Type: multipart/mixed" .
> "; boundary = $boundary\r\n\r\n";
> $headers .= "This is a MIME encoded message.\r\n\r\n";
> $headers .= "--$boundary\r\n" .
> "Content-Type: text/html; charset=ISO-8859-1\r\n" .
> "Content-Transfer-Encoding: 7bit\r\n\r\n";
> }
>
> else {
> $headers = "From: $from\r\n";
> }
>
> $success = mail ($to, $_email_subject, $_email_message, $headers);
> if ($success) {
> $popup_address = "sent: ".$to."<br/>";
> print "<script type=\"text/javascript\">var popupAddress = \"<?php
> echo $popup_address;
> ?>\";newListWindow.document.write(popupAddress);</script>";
> sleep ($_emaildelay * 60);
> }
> else {
> $failed[$f] = $to;
> $f++;
> }
> }
>
> if ($failed > 0) {
> print '<script type=\"text/javascript\">alert (\"Failure Sending
> Email\");</script>';
> print "The following addresses did not send:\r\n";
> foreach ($failed as $key => $value) {
> print $failed[$key]."\r\n";
> }
> }
> }
>
> if ($_POST['submit_check']) {
> $valid = emailcheck ($email_from);
> if (!$valid) {
> print "<script type=\"text/javascript\">alert('Please enter a valid
> email address in the EMAIL FROM field');</script>";
> }
> else {
> $email_message =
> file_get_contents($_FILES['message_file']['tmp_name']) or
> die($errors['cant_open_message']);
> $address_file = file($_FILES['address_file']['tmp_name']) or
> die($errors['cant_open_address']);
> sendmail ($address_file, $email_from, $email_from_name,
> $email_subject, $email_message, $_POST['mime_type']);
> }
> showform ($email_from, $email_subject,
> $_FILES['address_file']['name'], $_FILES['message_file']['name'],
> $email_delay, $_POST['mime_type']);
> }
> else {
> showform ($email_from, $email_subject,
> $_FILES['address_file']['name'], $_FILES['message_file']['name'],
> $email_delay, $_POST['mime_type']);
> }
> ?>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация