Jump to content

Problem with Form to Email script


All4172

Recommended Posts

very odd problem that I am not able to figure out.  When I hard code the $recipients like so:

 

$recipients = "onerecip|[email protected]";

 

Everything works fine.  However if I try to use the following:

 

$recipients = "onerecip|".$_GET['mail'];

 

It spits out that it can't connect to mail server.

 

Both times when I echo the $recipients it echo's the correct email.  Entire script is as follows, any ideas?

 

<?php
session_start();

// --------------------------------
// START OF OPTIONS
// --------------------------------


// RECIPIENTS
// ----------
// One:       "onerecip|(email)"
// Multiple:  "mulrecip|(cc or bcc)|(email 1)|(email 2)  etc.. "
// Drop-down: "selrecip"  
// (the drop-down data must be added to the form structure below)

$recipients = "onerecip|".$_GET['mail'];



// FORM STRUCTURE
// --------------

$form_structure = array(	
"openfieldset|fmset",
"info|fminfofull|Send me an email...",
"text|fmtext|Name|fm_name|32|100|true|none",
"text|fmtext|Email|fm_email|32|100|true|email",
"text|fmtext|Subject|fm_subject|32|100|false|none",
"text|fmtext|Verify|fm_verify|7|5|true|none",
"textarea|fmtextarea|Message|fm_message|6 |26 |true",
"closefieldset"
);


// SPECIAL FIELDS
// ----------------
// This lets the script know the names of the 'special' fields
//
// VERIFICATION FIELD
// To disable verification, set this to "", and 
// remove the verification line from the form structure

$field_verification = "fm_verify";

// EMAIL HEADER FIELDS
// These are the fields that will be used to generate the header
// for the email(s). If these are set to "", the email will use
// the default values (and you will not see the user's info in
// the email header - only in the message)

$field_name = "fm_name";
$field_subject = "fm_subject";
$field_email = "fm_email";

// DROP DOWN RECIPIENT
// Only applies if you are using a drop down to select a recipient

$field_dropdownrecip = "fm_sendto";



// FORM OPTIONS
// ------------
// SHOW USER WHICH FIELDS ARE REQUIRED
//
// If enabled, this will put an asterisk next to required fields.
// (styled with .fmrequired)

$show_required = TRUE;



// MESSAGE GENERATION
// ------------------

// SUBJECT [PREFIX]
// If you ask for a subject, this will be its prefix.
// If not, this will be the complete subject line.

$subject = 'Website Contact: ';

// SHOW HEADER FIELDS IN MESSAGE
// If using name, email, and/or subject fields in the email header, 
// disabling this option will keep those fields from being shown in the 
// body of the message. (since the information will already be in the header)

$show_headers_in_message = FALSE;

// SHOW VERIFICATION CODE IN MESSAGE
// If enabled, this will show the entered code in the email.

$show_code_in_message = FALSE;

// WRAP MESSAGES
// Required to meet RFC specifications (70 characters per line).

$wrap_messages = TRUE;

// INCLUDE IP
// If enabled, adds the sender's IP and host info to the message

$include_ip = FALSE;



// LANGUAGE OPTIONS
// ----------------

// SERVER ERROR MESSAGE
// Shown when message cannot be sent (do not use html tags).

$msg_mailserver = "No connection to the mailserver. Please try again later.";

// SUCCESS MESSAGE
// Shown when message has been sent (you can use html tags).

$msg_sent = "<h2>Thank you!</h2><p>Your message has been sent!</p>";

// FORM ERROR MESSAGE
// Shown when there is a mistake on the form 
// (do not use html tags - styled with .fmerrortitle).

$msg_error = "Error!";

// SUBMIT BUTTON
// The text for the send button (do not use html tags).

$msg_submit = "Send Email";






// --------------------------------
// END OF OPTIONS
// --------------------------------



// --------------------------------
// CSS DECLARATIONS
// --------------------------------

// It is best to put these declarations in your main style sheet
// Since it is not always proper to have CSS declarations in the middle
// of a file. 

// In the form structure above, you can specify custom class names
// for each input field if you like.

?>


<style type="text/css">
<!--


.mailwrapper {
text-align: center;
}


.maildiv {
margin: 0 auto 0 auto;
text-align: left;
width: 365px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 90%;
}
.maildiv form {
text-align: left;
}
.maildiv label {
/* used for right side captions */
vertical-align: top;
padding: 0 0 0 3px;
}

.maildiv .sidelbl {
/* used for left side labels */
width: 95px;
text-align: right;
padding: 0 10px 0 0;
vertical-align: top;
position: relative;
    display: block; 
    float: left; 
clear: left;
}
.maildiv a {
color: #005ABE;
}
.maildiv h2 {
color: #005ABE;
font-size: 120%;
}
.maildiv input {
margin-bottom: 10px;

}
.maildiv select {
margin-bottom: 10px;

}
.maildiv textarea {
margin-bottom: 10px;

}
.maildiv .ver_img {
padding: 0;
margin: 0 0 10px 10px;
vertical-align:bottom;  
border: 1px solid #005ABE; 
}
.maildiv fieldset {
padding: 5px 5px 5px 5px;
margin-bottom: 10px;
}
.maildiv .legendspacing {
height: 10px;
}
.maildiv .fmcredits {
float: left;
font-size: 90%;
}
.maildiv .fmsubmit {
float: right;
}
.maildiv .fmrequired {
color: #005ABE;
font-size: 90%; 
float: left;
margin-top: 3px;
margin-left: 5px;
}
.maildiv .fmspacer {
height: 10px;
}

.maildiv .fminfofull {
padding: 0 10px 0 10px;
color: #005ABE;
margin-bottom: 15px;
}
.maildiv .fminfohalf {
padding: 0 10px 0 10px;
color: #005ABE;
margin-left: 110px;
margin-bottom: 15px;
}
.maildiv .fmerrorbox {
text-align: left;
}
.maildiv li {
margin: 0 0 4px 0;
}
.maildiv .fmerrortitle {
color: #FF0000;
font-size: 120%;
}

-->
</style>


<?php

// --------------------------------
// END OF CSS DECLARATIONS
// --------------------------------





// Do not edit anything below unless you know what you are doing 


$email_sent = FALSE;
$t_out = "";


// turn $recipients into a useable array
$recipients = explode("|", $recipients);
for ($i = 0; $i < count($recipients); $i++) {
$recipients[$i] = trim($recipients[$i]);
}

// turn form fields into a useable array
for ($i = 0; $i < count($form_structure); $i++) {
$form_structure[$i] = explode("|", $form_structure[$i]);
for ($j = 0; $j < count($form_structure[$i]); $j++) {
	$form_structure[$i][$j] = trim($form_structure[$i][$j]);
}
}


function is_valid_url($link) { 
// returns TRUE if url actually exists

if (strpos($link, "http://") === FALSE) { $link = "http://" . $link; }
    $url_parts = @parse_url($link);
if (empty($url_parts["host"])) return( false );
if (!empty($url_parts["path"])) { $documentpath = $url_parts["path"]; } 
    else { $documentpath = "/"; }
if (!empty($url_parts["query"])) { $documentpath .= "?" . $url_parts["query"]; }
$host = $url_parts["host"];	$port = $url_parts["port"];
if (empty($port)) $port = "80";
$socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
if (!$socket) {	return(false); } 
    else {fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
$http_response = fgets( $socket, 22 );
if (ereg("200 OK", $http_response, $regs)) { return(true); fclose($socket);	} 
else { return(false); } }
}


function is_valid_email($email) {
// returns TRUE if email address is valid

$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
	'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}


function injection_chars($s) {
// returns TRUE if 'bad' characters are found
return (eregi("\r", $s) || eregi("\n", $s) || eregi("%0a", $s) || eregi("%0d", $s)) ? TRUE : FALSE;
}


function generate_verification() {
srand((double)microtime()*1000000); 
$rand = rand(0,999999999);  
$thecode = substr(strtoupper(md5($rand)), 2, 5); 
$thecode = str_replace("O", "A", $thecode);
$thecode = str_replace("0", "B", $thecode);
$_SESSION["thecode"] = $thecode;
}

function strip_colons($s) {
return str_replace(array(':', '%3a'), " ", $s);
}


$first_load = TRUE;

if (isset($_POST["form_submitted"])) {
// if the form has been submitted

$first_load = FALSE;

// prepare error list
unset($errors);


// prepare mail variables
$mail_message = "";
$mail_name = "Anonymous";
$mail_subject = $subject;
$mail_email = '[email protected]';


// process input
foreach ($form_structure as $form_field) {


switch ($form_field[0]) {

case "text":
case "password":

	$f_type = $form_field[0];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_max = $form_field[5];
	$f_req = $form_field[6];
	$f_ver = $form_field[7];

	// get data
	$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
	if (get_magic_quotes_gpc()) {
		$t = stripslashes($t);
	}

	// check for size limits
	if (strlen($t) > $f_max) {
		$errors[] = "There is a $f_max character limit for '$f_name'.";
	}

	// check for required fields
	if (($f_req == "true") && ($t == "")) {
		if ($f_fmname != $field_verification) { // has it's own check
			$errors[] = "Missing required field: '$f_name'.";
		}
	}

	// check for injection characters
	if (($f_type != "textarea") && (injection_chars($t))) {
		$errors[] = "Invalid input in '$f_name'!";
	}

	// check for valid email (if present/required)
	if (($f_ver == 'email') && ($f_req == "true" || (trim($t) != ""))) {
		if (!is_valid_email($t)) {
			$errors[] = "Invalid email address: '$f_name'";
		}
	}
	// check for valid url (if present/required)
	if (($f_ver == 'url') && ($f_req == "true" || (trim($t) != ""))) {
		if (!is_valid_url($t)) {
			$errors[] = "Invalid link: '$f_name'";
		}
	}


	// check for headers/verification fields
	if ($f_fmname == $field_name) {

		if ($t != "") {
			$mail_name = strip_colons($t);
			if ($show_headers_in_message)
				$mail_message .= $f_name . ' = ' . $t . "\n\n";
		}

	} elseif ($f_fmname == $field_subject) {

		if ($t != "") {
			$mail_subject = $subject . strip_colons($t);
			if ($show_headers_in_message)
				$mail_message .= $f_name . ' = ' . $t . "\n\n";
		}

	} elseif ($f_fmname == $field_email) {

		if ($t != "") {
			$mail_email = strip_colons($t);
			if ($show_headers_in_message)
				$mail_message .= $f_name . ' = ' . $t . "\n\n";
		}

	} elseif ($f_fmname == $field_verification) {

		if ($t == "") { 
			$errors[] = "Enter the verification code!";
		} else if (trim($_SESSION["thecode"]) == "") { 
			$errors[] = "No verification code generated!";
		} else if ($_SESSION["thecode"] != strtoupper($t)) { 
			$errors[] = "Invalid verification code!";
		} else {
			if ($show_code_in_message)
				$mail_message .= $f_name . ' = ' . $t . "\n\n";
		}

	} else {

		if ($t != "") {
			$mail_message .= $f_name . ' = ' . $t . "\n\n";
		}

	}	


	break;


case "textarea":

	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_req = $form_field[6];

	// get data
	$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
	if (get_magic_quotes_gpc()) {
		$t = stripslashes($t);
	}

	// check for required fields
	if (($f_req == "true") && ($t == "")) {
		if ($f_fmname != $field_verification) { // has it's own check
			$errors[] = "Missing required field: '$f_name'.";
		}
	}

	if ($t != "") {
		$mail_message .= $f_name . " = \n" . $t . "\n\n";
	}

	break;


case "checkbox":

	$f_name = $form_field[2];

	$t_message = $f_name . ' =';

	$f = FALSE;
	for ($i = 3; $i < count($form_field); $i+=3) {
		$f_fmname = $form_field[$i];
		$f_caption = $form_field[$i+1];

		$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";
		if ($t == 'on') {
			$t_message .= " " . $f_caption . ","; 
			$f = TRUE;
		}
	}

	$t_message = rtrim($t_message, ',');

	if ($f) {
		$mail_message .= $t_message . "\n\n";
	}

	break;


case "radio":

	$f_name = $form_field[2];
	$f_fmname = $form_field[3];

	$t = (isset($_POST[$f_fmname])) ? trim($_POST[$f_fmname]) : "";

	$f = FALSE;
	for ($i = 5; $i < count($form_field); $i+=2) {
		if ($t == $form_field[$i]) {
			$f = TRUE;
		}
	}

	if ($f) {
		$mail_message .= $f_name . ' = ' . $t . "\n\n";
	}

	break;


case "select":

	$f_name = $form_field[2];
	$f_fmname = $form_field[3];

	$t_message = $f_name . ' =';

	$t = (isset($_POST[$f_fmname])) ? $_POST[$f_fmname] : "";

	foreach ((array)$t as $tt) {

		$f = FALSE;		
		for ($i = 6; $i < count($form_field); $i++) {
			if (($form_field[$i] == $tt) && (trim($tt) != "")) {
				$f = TRUE;
			}
		}
		if ($f) {
			$t_message .= ' ' . $tt . ',';
		}

	}


	$t_message = rtrim($t_message, ',');

	if ($f) {
		$mail_message .= $t_message . "\n\n";
	}

	break;


}

}


// if no errors, process
if (empty($errors)) {

	$mail_message = trim($mail_message);

	// wrap messages if set
	if ($wrap_messages) {
		$mail_message = wordwrap($mail_message, 70);
	}


	// prepare the headers
	// \r\n seems to be the best method for most servers to handle
	$ip = $_SERVER["REMOTE_ADDR"];
	$mail_header = "";
	$mail_header .= "MIME-Version: 1.0\r\n"; 
	$mail_header .= "X-Sender-IP: $ip\r\n";
	$mail_header .= "Content-Type: text/plain\r\n";
	$mail_header .= "From: " . $mail_name . " <" . $mail_email . ">";


	if ($recipients[0] == 'onerecip') {

		$mail_to = $recipients[1];

	} elseif ($recipients[0] == 'mulrecip') {

		$mail_to = $recipients[2];
		for ($i = 3; $i < count($recipients); $i++) {

			$mail_header .= "\r\n";
			if ($recipients[1] == 'cc') {
				$mail_header .= "Cc: ";
			} else {
				$mail_header .= "Bcc: ";
			}
			$mail_header .= $recipients[$i];
		}

	} elseif ($recipients[0] == 'selrecip') {

		$recip_number = (int)$_POST[$field_dropdownrecip];
		foreach ($form_structure as $form_field) {
			if ($form_field[0] == 'selrecip') {
				$j = 1;
				for ($i = 4; $i < count($form_field); $i++) {
					if (strpos($form_field[$i], "#") === 0) {
						$i++;
					}
					$i++;
					if ($recip_number == $j) {
						$mail_to = $form_field[$i];
					}
					$j++;
				}
			}
		}
	} 


	// send mail, setting $email_sent to true or false


		if ($include_ip) {
			$mail_message .= "\n";
			$mail_message .= "\nHost: " . $_SERVER["HTTP_HOST"];
			$mail_message .= "\nIP: " . $_SERVER["REMOTE_ADDR"];
			$mail_message .= "\nBrowser: " . $_SERVER["HTTP_USER_AGENT"];
		}


	if (mail($mail_to, $mail_subject, $mail_message, $mail_header, "-f $mail_email")) {
		$email_sent = true; 
	} else {
		$errors[] = $msg_mailserver;
		$email_sent = false;
	}

}


if (isset($errors)) {

	// if there were errors, list them

	$t_out .= '<div class="mailwrapper"><div class="maildiv"><div class="fmerrorbox">';
	$t_out .= '<p class="fmerrortitle">' . $msg_error . '</p><ul>';

	foreach ($errors as $f)
		$t_out .= '<li>' . $f . '</li>';

	$t_out .= '</ul></div></div></div>';

} else {

	// the message was sent, display message


	$t_out .= '<div class="mailwrapper"><div class="maildiv">';

	$t_out .= $msg_sent;

	$t_out .= '</div></div>';

	generate_verification();

}

}





if (!$email_sent) {

// SHOW FORM

generate_verification();

if (!extension_loaded("gd")) {
   $t_out .= "<p><b>GD Support not detected!</b> GD is required for this script.</p>";
}

$t_out .= '<div class="mailwrapper"><div class="maildiv">';
$t_out .= '<form method="post" action="' . basename($_SERVER["PHP_SELF"]) . '" enctype="multipart/form-data">';


// go through fields
foreach ($form_structure as $form_field) {


// process field types
switch ($form_field[0]) {


case "openfieldset":

	$f_class = $form_field[1];

	$t_out .= '<fieldset class="' . $f_class . '">';

	if (count($form_field) > 2) {

		$f_legend = $form_field[2];

		$t_out .= '<legend>' . $f_legend . '</legend><div class="legendspacing"></div>';
	}

	break;


case "closefieldset":

	$t_out .= '</fieldset>';

	break;


case "info":

	$f_class = $form_field[1];
	$f_text = $form_field[2];

	$t_out .= '<div class="' . $f_class . '">' . $f_text . '</div>';

	break;


case "text":

	$f_class = $form_field[1];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_size = $form_field[4];
	$f_max = $form_field[5];
	$f_req = $form_field[6];

	$t_out .= '<label class="sidelbl" for="' . $f_fmname . '">';
	if (($f_req == "true") && ($show_required)) 
		$t_out .= '<span class="fmrequired">* </span>';
	$t_out .= $f_name . '</label>';

	$t_out .= '<input type="text" class="' . $f_class . '" name="' . $f_fmname . '" 
				id="' . $f_fmname . '" size="' . $f_size . '" maxlength="' . $f_max . '"';

	if (isset($_POST[$f_fmname])) {
		if ($f_fmname != $field_verification) {
			$t_out .= ' value="' . htmlspecialchars($_POST[$f_fmname]) . '"';
		}
	}

	$t_out .= ' />';

	if ($f_fmname == $field_verification) {
		$t_out .= '<img class="ver_img" src="formmailer_verify.php" width="60" height="20" alt="Please enter the number from this image" />';
	}

	$t_out .= '<br />';

	break;


	case "password":

	$f_class = $form_field[1];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_size = $form_field[4];
	$f_max = $form_field[5];
	$f_req = $form_field[6];

	$t_out .= '<label class="sidelbl" for="' . $f_fmname . '">';
	if (($f_req == "true") && ($show_required)) 
		$t_out .= '<span class="fmrequired">* </span>';
	$t_out .= $f_name . '</label>';

	$t_out .= '<input type="password" class="' . $f_class . '" name="' . $f_fmname . '" 
				id="' . $f_fmname . '" size="' . $f_size . '" maxlength="' . $f_max . '"';

	if (isset($_POST[$f_fmname])) {
		if ($f_fmname != $field_verification) {
			$t_out .= ' value="' . htmlspecialchars($_POST[$f_fmname]) . '"';
		}
	}

	$t_out .= ' /><br />';

	break;


case "textarea":

	$f_class = $form_field[1];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_rows = $form_field[4];
	$f_cols = $form_field[5];
	$f_req = $form_field[6];

	$t_out .= '<label class="sidelbl" for="' . $f_fmname . '">';
	if (($f_req == "true") && ($show_required)) 
		$t_out .= '<span class="fmrequired">* </span>';
	$t_out .= $f_name . '</label>';

	$t_out .= '<textarea class="' . $f_class . '" name="' . $f_fmname . '" 
				id="' . $f_fmname . '" rows="' . $f_rows . '" cols="' . $f_cols . '" >';

	if (isset($_POST[$f_fmname])) {
		if ($f_fmname != $field_verification) {
			$t_out .= htmlspecialchars($_POST[$f_fmname]);
		}
	}

	$t_out .= '</textarea><br />';

	break;


case "checkbox":

	$f_class = $form_field[1];
	$f_name = $form_field[2];

	$t_out .= '<label class="sidelbl">' . $f_name . '</label>';

	for ($i = 3; $i < count($form_field)-1; $i+=3) {
		if ($i > 3) {
			$t_out .= '<label class="sidelbl"> </label>';
		}

		$f_fmname = $form_field[$i];
		$f_caption = $form_field[$i+1];
		$f_checked = $form_field[$i+2];

		$t_out .= '<input class="' . $f_class . '" type="checkbox" name="' . $f_fmname . '" id="' . $f_fmname . '"';

		if ($first_load) {
			if ($f_checked == 'true') {
				$t_out .= ' checked="checked" ';
			}
		} else {
			if (isset($_POST[$f_fmname])) {
				if ($_POST[$f_fmname] == "on") {
					$t_out .= ' checked ';
				} 	
			} 
		}

		$t_out .= ' />';
		$t_out .= '<label for="' . $f_fmname . '">' . $f_caption . '</label> <br />';
	}

	break;


case "radio":

	$f_class = $form_field[1];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_def = $form_field[4];

	$t_out .= '<label class="sidelbl">' . $f_name . '</label>';

	$j = 1;
	for ($i = 5; $i < count($form_field); $i+=2) {

		$f_value = $form_field[$i];
		$f_caption = $form_field[$i+1];

		if ($i > 5) {
			$t_out .= '<label class="sidelbl"> </label>';
		}
		$t_out .= '<input class="' . $f_class . '" type="radio" name="' . $f_fmname . '" id="' . $f_fmname . $j . '" value="' . $f_value . '"';


		if ($first_load) {
			if ((int)$f_def == $j) {
				$t_out .= ' checked="checked" ';
			}
		} else {

			if (isset($_POST[$f_fmname])) {
				if ($_POST[$f_fmname] == $f_value) {
					$t_out .= ' checked="checked" ';
				} 	
			} 
		}

		$t_out .= ' />';
		$t_out .= '<label for="' . $f_fmname . $j . '">' . $f_caption . '</label> <br />';

		$j++;
	}

	break;


case "select":

	$f_class = $form_field[1];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];
	$f_mul = $form_field[4];

	$t_out .= '<label class="sidelbl" for="' . $f_fmname . '">' . $f_name . '</label>';
	$t_out .= '<select class="' . $f_class . '" name="' . $f_fmname;
	if ($f_mul === "true") {
		$t_out .= '[]';
	}	
	$t_out .= '" id="' . $f_fmname . '"';
	if ($f_mul === "true") {
		$t_out .= ' multiple="multiple" ';
	}

	$t_out .= '>';

	$grp_count = 0;
	for ($i = 5; $i < count($form_field)-1; $i++) {

		if (strpos($form_field[$i], "#") === 0) {

			if ($grp_count > 0) {
				$t_out .= "</optgroup>";
			}

			$t_out .= '<optgroup label="' . ltrim($form_field[$i], "#") . '">';

			$grp_count++;
			$i++;
		}

		$t_out .= '<option value="' . $form_field[$i] . '"';

		if ($f_mul == "true") {
			if (isset($_POST[$f_fmname])) {
				foreach ($_POST[$f_fmname] as $p) {
					if ($p == $form_field[$i]) {
						$t_out .= ' selected';
					} 
				}
			} 		
		} else {
			if (isset($_POST[$f_fmname])) {
				if ($_POST[$f_fmname] == $form_field[$i]) {
					$t_out .= ' selected';
				} 	
			} 		
		}


		$t_out .= ' > ' . $form_field[$i+1] . '</option>';

		$i++;

	}

	if ($grp_count > 0) {
		$t_out .= "</optgroup>";
	}
	$t_out .= '</select><br />';

	break;


case "selrecip":

	$f_class = $form_field[1];
	$f_name = $form_field[2];
	$f_fmname = $form_field[3];

	$t_out .= '<label class="sidelbl" for="' . $f_fmname . '">' . $f_name . '</label>';
	$t_out .= '<select class="' . $f_class . '" name="' . $f_fmname . '" id="' . $f_fmname . '" >';


	$j = 1;
	$grp_count = 0;
	for ($i = 4; $i < count($form_field)-1; $i++) {

		if (strpos($form_field[$i], "#") === 0) {

			if ($grp_count > 0) {
				$t_out .= "</optgroup>";
			}

			$t_out .= '<optgroup label="' . ltrim($form_field[$i], "#") . '">';

			$grp_count++;
			$i++;
		}

		$t_out .= '<option value="' . $j . '"';


		if (isset($_POST[$f_fmname])) {
			if ($_POST[$f_fmname] == $j) {
				$t_out .= ' selected';
			} 	
		} 		

		$t_out .= ' > ' . $form_field[$i] . '</option>';

		$i++;
		$j++;
	}

	if ($grp_count > 0) {
		$t_out .= "</optgroup>";
	}
	$t_out .= '</select><br />';

	break;

}	
}

$t_out .= '<div class="fmspacer"><!-- --></div>';

$t_out .= '<div class="fmsubmit"><input name="form_submitted" type="submit" id="Submit" value="' . $msg_submit . '" /></div>';

$t_out .= '</form></div></div>';

$t_out .= 'Email:';

$t_out .= $recipients[1];

}




echo $t_out;


?>

Link to comment
https://forums.phpfreaks.com/topic/39865-problem-with-form-to-email-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.