Go Back   Novahq.net Forum > phphq.Net > phphq.Net Forums

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-10-2005, 12:00 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,275

Don't get the drop down box? Look here.

I know i'm going to get questions on this so i'm going to explain it a bit better here without cluttering up the text in the script.

Drop down box usage:

First make sure you set $use_subject_drop to true, eample:

$use_subject_drop=true;

Next fill in the subjects you want to show in the drop down box. Example:

Example 1
PHP Code:
$subjects=array("Sales Department","Customer Service","Tech Support");
$emails=array("sales@domain.com","cust_service@domain.com","tech_support@domain.com"); 
Example 2
PHP Code:
$subjects=array("Department 1","Department 2");
$emails=array("sales@domain.com","cust_service@domain.com"); 
Note!
There MUST be as many values in $subjects as there are in $emails. They also must be in the same order. If I switch around the [b:7a7465bf48]Example 1[/b:7a7465bf48] you would have to re-order the emails also!

Example 3
PHP Code:
$subjects=array("Tech Support","Customer Service","Sales Department");
$emails=array("tech_support@domain.com","cust_service@domain.com","sales@domain.com"); 
If you have any more questions please post in this thread.
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #2  
Old 03-23-2006, 08:26 AM
nraum
Unregistered

Posts: n/a

Do you know of an easy way to display a specific category by default from another page. For example, if a user clicks on Helpdesk, it will auto-select Helpdesk from the Department drop-down.

Thanks,
narayan
Reply With Quote
  #3  
Old 03-23-2006, 03:48 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,275

On line 528

Change this:
PHP Code:
<form method="post" action="><?=$_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" name="phmailer" onsubmit="return Checkit(this);">
To this:
PHP Code:
<form method="post" action=">?=$_SERVER['PHP_SELF'];?>?mail=>?=$_GET['mail'];?>" enctype="multipart/form-data" name="phmailer" onsubmit="return Checkit(this);"
And Line 557:

Change this:
PHP Code:
<?
while(list($key,$val)=each($subjects)) {?>

            <option value="<?=intval($key);?>"><?=htmlspecialchars(stripslashes($val));?></option>

<?}?>

To This:
PHP Code:
<?
while(list($key,$val)=each($subjects)) {
    If(
$_GET['mail']==$val) {
        
$selected=" selected=\"selected\"";
    } Else {
        
$selected="";
    }

?>

<option value="<?=intval($key);?>"<?=$selected;?>><?=htmlspecialchars(stripslashes($val));?></option>


<?}?>
And then when you link to the mail form, use something like this: phMailer.php?mail=HelpDesk, or phMailer.php?mail=Customer_Service
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #4  
Old 09-20-2007, 02:50 PM
justoneproblem is offline justoneproblem
Registered User

Join Date: Sep 2007
Posts: 1

hehe it did not work

Hi, just install the script on my server. I try out the mailtest and manage to send an email. However when finish editing phMailer.php and uploaded it to the server, I was not able to send any message plus the drop down box did not appear. I have paste the edited PhMailer.php, any suggestion would be great

Code:
<?php
error_reporting(0);
/*
//================================================================================
* phphq.Net Custom PHP Scripts *
//================================================================================
:- Script Name: phMailer
:- Version: 1.5
:- Release Date: Jan 27th 2004
:- Last Update: Dec 9th 2005
:- Author: Scott L. <scott@phphq.net> http://www.phphq.net
:- Copyright(c) 2005 All Rights Reserved
:-
:- This script is free software; you can redistribute it and/or modify
:- it under the terms of the GNU General Public License as published by
:- the Free Software Foundation; either version 2 of the License, or
:- (at your option) any later version.
:-
:- This script is distributed in the hope that it will be useful,
:- but WITHOUT ANY WARRANTY; without even the implied warranty of
:- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
:- GNU General Public License for more details.
:-http://www.gnu.org/licenses/gpl.txt

// This will show in the <title></title> and the form name
$websitename="Dedicate A Song"; 

// Allowed file types. Please remember to keep the format of this array, add the file extensions you want WITHOUT the dot. Please also be aware that certain file types may cause harm to your website and/or server.
$allowtypes=array("zip", "7zip");

// What's your email address? Seperate email addresses with commas for multiple email addresses.
$myemail="email1@myemail.com";

// What priority should the script send the mail? 1 (Highest), 2 (High), 3 (Normal), 4 (Low), 5 (Lowest).
$priority="3"; 

// Should we allow visitors to attach files? How Many? 0 = Do not allow attachments, 1 = allow only 1 file to be attached, 2 = allow two files etc.
$allowattach="1"; 

// Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handel it, post_max_size, upload_max_filesize, file_uploads, max_execution_time!
// 2048kb = 2MB,       1024kb = 1MB,     512kb = 1/2MB etc..
$max_file_size="1024";

// Maximum file size for all attachments combined in KB NOT Bytes! MAKE SURE your php.ini can handel it, post_max_size, upload_max_filesize, file_uploads, max_execution_time!
// 2048kb = 2MB,       1024kb = 1MB,     512kb = 1/2MB etc..
$max_file_total="2048";

// Value for the Submit Button
$submitvalue=" Dedicate "; 

// Value for the Reset Button
$resetvalue=" Reset ";

// Default subject? This will be sent if the user does not type in a subject
$defaultsubject="Song Dedication"; 

// Because many requested it, this feature will add a drop down box for the user to select a array of subjects that you specify below. 
// True = Use this feature, False = do not use this feature
$use_subject_drop=True;
musi
// This is an array of the email subjects the user can pick from. Make sure you keep the format of this array or you will get errors!
// Look at http://phphq.net/forums/viewtopic.php?p=836 for examples on how to use this feature.
$subjects=array("Request Song","Song Dedication","Send DJ an Email");

// This is an array of the email address for the array above. There must be an email FOR EACH array value specified above. You can have only 1 department if you want.
//YOU MUST HAVE THE SAME AMMOUNT OF $subjects and $emails or this WILL NOT work correctly! The emails also must be in order for what you specify above!
// You can also seperate the emails by a comma to sent 1 department to multiple email addresses.
$emails=array("email1@myemail.com","email2@myemail.com","email3@myemail.com");

$thanksmessage="Thank you! Your email has been sent, we will respond shortly."; 
$thanksmessage="<script type=\"text/javascript\">window.location=\"http://www.domain.com/tky.html\";</script>"; 
// Uncomment (remove the //'s) above to use redirect



/*
//================================================================================
* ! ATTENTION !
//================================================================================
: Don't edit below this line unless you know some php. Editing some variables or other stuff could cause undeseriable results!!
*/

// Will get the extension of the users file. For some reason trying to get the actual type of the file caused problems with certain browsers.

function get_ext($key) { 
	$key=strtolower(substr(strrchr($key, "."), 1));
	// Cause there the same right?
	$key=str_replace("jpeg","jpg",$key);
	return $key;
}

function phattach($file,$name) {
	global $boundary;
	
	$fp=@fopen($file,"r");
	$str=@fread($fp, filesize($file));
	$str=@chunk_split(base64_encode($str));
	$message="--".$boundary."\n";
	$message.="Content-Type: application/octet-stream; name=\"".$name."\"\n";
	//$message.="Content-disposition: attachment\n"; Thanks goes to someone named Chris (I think, it was awhile ago) for his fix below!
	$message.="Content-disposition: attachment; filename=\"".$name."\"\n"; 
	$message.="Content-Transfer-Encoding: base64\n";
	$message.="\n";
	$message.="$str\n";
	$message.="\n";

	return $message;
}

//Little bit of security from people forging headers. People are mean sometimes :(
function clean($key) {
	$key=str_replace("\r", "", $key);
	$key=str_replace("\n", "", $key);
	$find=array(
		"/bcc\:/i",
		"/Content\-Type\:/i",
		"/Mime\-Type\:/i",
		"/cc\:/i",
		"/to\:/i"
	);
  $key=preg_replace($find,"",$key);
  return $key;
}

// Safe for register_globals=on =)

$error="";
$types="";
$sent_mail=false;

// Do some loopy stuff for the valid file types so people can see what types are valid before they try and upload invalid ones.

$ext_count=count($allowtypes);
$i=0;

foreach($allowtypes AS $extension) {
	
	//Gets rid of the last comma
	
	If($i <= $ext_count-2) {
		$types .="*.".$extension.", ";
	} Else {
		$types .="*.".$extension;
	}
	$i++;
}
unset($i,$ext_count); // why not


// If they post the form start the mailin'!

If($_POST['submit']==true) {
	extract($_POST, EXTR_SKIP);

		// Check the form for errors
	
		If(trim($yourname)=="") { 
			$error.="You did not enter your name!<br />";
		}
		
		If(trim($youremail)=="") { 
			$error.="You did not enter your email!<br />";
		} Elseif(!eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$",$youremail)) {
			$error.="Invalid email address.<br />";
		}

		If(trim($emailsubject)=="") {
			$emailsubject=$defaultsubject;
		}

		If(trim($yourmessage)=="") { 
			$error.="You did not enter a message!<br />";
		}
		
		// Verify Attchment info
		
		If($allowattach > 0) {
			
			//Loopish
			
			For($i=0; $i <= $allowattach-1; $i++) {
				
				If($_FILES['attachment']['name'][$i]) {
					
					$ext=get_ext($_FILES['attachment']['name'][$i]);
					$size=$_FILES['attachment']['size'][$i];
					$max_bytes=$max_file_size*1024;
					
					//Check if the file type uploaded is a valid file type. 
					
					If(!in_array($ext, $allowtypes)) {
						
						$error.= "Invalid extension for your file: ".$_FILES['attachment']['name'][$i].", only ".$types." are allowed.<br />";
						
						//Check the size of each file
						
					} Elseif($size > $max_bytes) {
						$error.= "Your file: ".$_FILES['attachment']['name'][$i]." is to big. Max file size is ".$max_file_size."kb.<br />";
					}
					
				} // If Files
				
			} // For

			//Tally the size of all the files uploaded, check if it's over the ammount.
			
  			$total_size=array_sum($_FILES['attachment']['size']);
  			
			$max_file_total_bytes=$max_file_total*1024;
			
			If($total_size > $max_file_total_bytes) {
				$error.="The max size allowed for all your files is ".$max_file_total."kb<br />";
			}
			
		} // If Allowattach

	If($error) {
	
		$display_message=$error;

	} Else {
		
		If($use_subject_drop AND is_array($subjects) AND is_array($emails)) {
			$subject_count=count($subjects);
			$email_count=count($emails);
			
			If($subject_count==$email_count) {
				
				$myemail=$emails[$emailsubject];
				$emailsubject=$subjects[$emailsubject];
				
			}
			
		}
		
		
		$boundary=md5(uniqid(time()));
		
		//Little bit of security from people forging headers. People are mean sometimes :(
		
		$yourname=clean($yourname);
		$yourmessage=clean($yourmessage);
		$youremail=clean($youremail);
		
		//Headers
		
		$headers="From: ".$yourname." <".$youremail.">\n";
		$headers.="Reply-To: ".$yourname." <".$youremail.">\n";
		$headers.="MIME-Version: 1.0\n";
		$headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
		$headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
		$headers.="X-Mailer: PHP/".phpversion()."\n";
		$headers.="X-Priority: ".$priority."\n"; 
		$headers.="Return-Path: <".$youremail.">\n";
		$headers.="This is a multi-part message in MIME format.\n";

		//Message
			
		$message = "--".$boundary."\n";
		$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
		$message.="Content-Transfer-Encoding: quoted-printable\n";
		$message.="\n";
		$message.="$yourmessage";
		$message.="\n";

		//Lets attach to something! =)
		
		If($allowattach > 0) {
			
			For($i=0; $i <= $allowattach-1; $i++) {
				
				If($_FILES['attachment']['name'][$i]) {
					
					$message.=phattach($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]);
					
				}
				
			} //For
			
		} // If
		
		
		// End the message
		
		$message.="--".$boundary."--\n";
		
		// Send the completed message
		
		If(!mail($myemail,$emailsubject,$message,$headers)) {
			
			Exit("An error has occured, please report this to the website administrator.\n");
			
		} Else {
		
			$sent_mail=true;
			
		}

	} // Else

} // $_POST

/*
//================================================================================
* Start the form layout
//================================================================================
:- Please know what your doing before editing below. Sorry for the stop and start php.. people requested that I use only html for the form..
*/
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $websitename; ?></title>

<style type="text/css">
	body{
		background-color:#FFFFFF;
		font-family: Verdana, Arial, sans-serif;
		font-size: 12pt;
		color: #000000;
	}
	
	.error_message{
		font-family: Verdana, Arial, sans-serif;
		font-size: 11pt;
		color: #FF0000;
	}
	
	.thanks_message{
		font-family: Verdana, Arial, sans-serif;
		font-size: 11pt;
		color: #000000;
	}
	
	a:link{
		text-decoration:none;
		color: #000000;
	}
	a:visited{
		text-decoration:none;
		color: #000000;
	}
	a:hover{
		text-decoration:none;
		color: #000000;
	}
	
	
	.table {
		border-collapse:collapse;
		border:1px solid #000000;
		width:500px;
	}
	
	.table_header{
		border:1px solid #070707;
		background-color:#C03738;
		font-family: Verdana, Arial, sans-serif;
		font-size: 11pt;
		font-weight:bold;
		color: #FFFFFF;
		text-align:center;
		padding:2px;
	}
	
	.attach_info{
		border:1px solid #070707;
		background-color:#EBEBEB;
		font-family: Verdana, Arial, sans-serif;
		font-size: 8pt;
		color: #000000;
		padding:4px;
	}
	
	
	.table_body{
		border:1px solid #070707;
		background-color:#EBEBEB;
		font-family: Verdana, Arial, sans-serif;
		font-size: 10pt;
		color: #000000;
		padding:2px;
	}
	
	
	.table_footer{
		border:1px solid #070707;
		background-color:#C03738;
		text-align:center;
		padding:2px;
	}
	
	
	input,select,textarea {
		font-family: Verdana, Arial, sans-serif;
		font-size: 10pt;
		color: #000000;
		background-color:#AFAEAE;
		border:1px solid #000000;
	}
	
	.copyright {
		border:0px;
		font-family: Verdana, Arial, sans-serif;
		font-size: 9pt;
		color: #000000;
		text-align:right;
	}
	
	form{
		padding:0px;
		margin:0px;
	}
</style>


<script type="text/javascript">
var error="";
e_regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;

function Checkit(theform) {
	
	if(theform.yourname.value=="") {
		error+="You did not enter your name\n";
	}
	
	if(theform.youremail.value=="") {
		error+="You did not enter your email\n";
	} else if(!e_regex.test(theform.youremail.value)) {
		error+="Invalid email address\n";
	}
		
	if(theform.yourmessage.value=="") {
		error+="You did not enter your message\n";
	}
	
	if(error) {
		alert('**The form returned the following errors:**\n\n' + error);
		error="";
		return false;
	} else {
		return true;
	}
}
</script>


</head>
<body>
<?If($display_message) {?>

<div align="center" class="error_message"><b><?=$display_message;?></b></div>
<br />

<?}?>

<?If($sent_mail!=true) {?>

<form method="post" action="<?=$_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" name="phmailer" onsubmit="return Checkit(this);">
<table align="center" class="table">
	<tr>
		<td colspan="2" class="table_header" width="100%"><?=$websitename;?></td>
	</tr>
	<?If($allowattach > 0) {?>
		<tr>
			<td width="100%" class="attach_info" colspan="2">
				<b>Valid Attachment Types:</b> <?=$types?><br />
				<b>Max size per file:</b> <?=$max_file_size?>kb.<br />
				<b>Max combined file size:</b> <?=$max_file_total?>kb.
			</td>
		</tr>
	<?}?>
	
	<tr>
		<td width="30%" class="table_body">Your Name:</td>
		<td width="70%" class="table_body"><input name="yourname" type="text" size="30" value="<?=stripslashes(htmlspecialchars($yourname));?>" /><span class="error_message">*</span></td>
	</tr>
	<tr>
		<td width="30%" class="table_body">Your Email:</td>
		<td width="70%" class="table_body"><input name="youremail" type="text" size="30" value="<?=stripslashes(htmlspecialchars($youremail));?>" /><span class="error_message">*</span></td>
	</tr>
	<tr>
		<td width="30%" class="table_body">Subject:</td>
		<td width="70%" class="table_body">
		
			<?If($use_subject_drop AND is_array($subjects)) {?>
					<select name="emailsubject" size="1">
						<?while(list($key,$val)=each($subjects)) {?>

							<option value="<?=intval($key);?>"><?=htmlspecialchars(stripslashes($val));?></option>
						
						<?}?>
					</select>
				
			
			<?} Else {?>
				
				<input name="emailsubject" type="text" size="30" value="<?=stripslashes(htmlspecialchars($emailsubject));?>" />
				
			<?}?>
			
		</td>
	</tr>

<?For($i=1;$i <= $allowattach; $i++) {?>
	<tr>
		<td width="30%" class="table_body">Attach File:</td>
		<td width="70%" class="table_body"><input name="attachment[]" type="file" size="30" /></td>
	</tr>
<?}?>

	<tr>
		<td colspan="2" width="100%" class="table_body">Your Message:<span class="error_message">*</span><br />
			<div align="center">
				<textarea name="yourmessage" rows="8" cols="60"><?=stripslashes(htmlspecialchars($yourmessage));?></textarea>
			</div>
		</td>
	</tr>
	<tr>
		<td colspan="2" width="100%" class="table_footer">
			<input type="hidden" name="submit" value="true" />
			<input type="submit" value="Send Dedication" /> &nbsp;
			<input type="reset" value="Reset" />
		</td>
	</tr>
</table>
</form>

<?} Else {?>

<div align="center" class="thanks_message"><?=$thanksmessage;?></div>
<br />
<br />

<?}?>

<?//Please leave this here.. it really dosen't make people hate you or make your site look bad.. ?>
<table class="table" style="border:0px;" align="center">
	<tr>
		<td><div class="copyright">&copy;<a href="http://www.phphq.net?script=phMailer" target="_blank" title="Form Mailer Powered By phMailer &lt;www.phphq.net&gt;">phMailer</a></div></td>
	</tr>
</table>
</body>
</html>

Thanks
Reply With Quote
  #5  
Old 08-03-2009, 02:25 PM
Gazza is offline Gazza
Registered User

Join Date: Jul 2009
Posts: 9

When using a drop down menu is it possible to ensure that one of the options is selected.

I am looking to change one of my existing forms to use this script as it gives me nore options.

The Selection option is not linked to an email address but is allows the use to select the Section there team competes in (Section A, Section B, Section C etc); however I want to ensure they make a Selection.

Is this possible

Many thanks
Reply With Quote
  #6  
Old 08-04-2009, 12:30 AM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,275

It's always possible to make sure they select something. phMailer by default makes sure they select a email subject from the drop down so i'm not quite sure if you mean add a custom check or what?
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #7  
Old 08-04-2009, 07:37 AM
Gazza is offline Gazza
Registered User

Join Date: Jul 2009
Posts: 9

I probably haven't explained what I'm looking at very well, so you might want to look at the initial page I have put up on my Website, www.stroudskittles.co.uk/resultcard.php.

The idea is that the team can scan in their Result Card and email it to the Result Secretary rather than send by post. Initially I'm running this for one Section only, but hope to expand it to other Sections. What I want to enusre is that the visitor selects an option from the Drop Down Menu rather than leave the default (i.e. selects the Competition, two teams and Date).

I can't work out how to do this with php, but then again I've only recently discovered php for forms.

Any assistance would be appreciated

Many thanks
Reply With Quote
  #8  
Old 08-04-2009, 09:19 AM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,275

See attached.
Attached Files
File Type: zip phMailer.zip (11.5 KB, 12 views)
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
drop gas price is a steal, don't let anyone know you did it lol Hellfighter Humor & Jokes 3 01-30-2008 06:03 PM
Drop-down menus Chrispy Web design and Programming 31 02-14-2007 12:27 AM
drop down menus-PLEASE HELP darkchaos Web design and Programming 8 07-20-2003 07:38 PM
THe-Drop-Zone Scott News 7 04-29-2002 06:21 PM


All times are GMT -5. The time now is 10:21 PM.




Powered by vBulletin®