View Single Post
  #5 (permalink)  
Old 03-25-2005, 08:05 AM
Biggles's Avatar
Biggles Biggles is offline
WebProWorld Member
 
Join Date: Aug 2004
Posts: 68
Biggles RepRank 1
Default

i have the script suggested by mikmik and it works in-so-far as to send me an email with all info inputted, it doesnt attach the picture tho. I get the file name of the attachment, but not the actual file.

It has been suggested that it may be due to the servers register_globals being off.

here is the code for the php processing script:
Code:
<?php // Copyright ©2005, Christine M. R.

// To change the settings, simply change "email@email.com" to the email address
// you wish for the emails to be sent to, and "Thanks for your email, 
// I'll get back on you later!" to the confirmation message you want to be shown
// when everything is working just fine and the message was sent! :)
// Please avoid use of quoation signs. (")
$myemail = "

submit@wingsofwar.org.uk


"; $thankyou = "


Thank you for your submission to Wings of War. :)

";


// Don't edit anything below this line, unless you know what you are doing :)


// Make sure nobody gets stuck in infinite loops.

if(!$_POST)
	die('Please don\'t access this file directly.');


// Remove all those linebreaks from the variables.

$myemail = str_replace("
",'',$myemail); 
$thankyou = str_replace("
",'',$thankyou);


// Gather all the required fields. Remove the REQUIRED part from their names.

while(list($key,$val) = each($_POST)) {
	if(stristr($key,'REQUIRED')){
		$key = str_replace('REQUIRED','',$key);
		$_POST[$key] = $val;
		if($val == ''){
			$missing[] = ''.$key.'';
		}
	}
}


// If there is a myemail value in the form, send the email to it instead!

if($_POST[myemail])
	$myemail = $_POST[myemail];

// Set default values if there exists none.

if($_POST[name]){ $name = $_POST[name]; } else { $name = "aMAILzing"; }
if($_POST[email]){ $email = $_POST[email]; } else { $email = $myemail; }
if($_POST[subject]){ $subject = $_POST[subject]; } else { $subject = "Web Form"; }

// Find all the fields, and add them to the email.

foreach($_POST as $k=>$v) {
	if($v && !stristr($k,'REQUIRED'))
		if(is_array($v))
			$message .= ucfirst($k).": ".implode(', ', $v)."\n\n";
		else
			$message .= ucfirst($k).": $v\n\n";
}

// Write the rest of the email body.

$message .= "-----------------------------------------------------------\n";
$message .= "Powered by aMAILzing - http://scripts.inexistent.org";
$message = stripslashes($message);


// Write the headers.

$mail_boundary = "x".md5(time())."x";
$header = "From: $name <$email>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: multipart/mixed; boundary=\"{$mail_boundary}\"\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-MSMail-Priority: Normal\r\n";
$header .= "X-Mailer: aMAILzing 0.9 http://scripts.inexistent.org\r\n";
$header .= "This is a multi-part message in MIME format.\r\n\r\n";
$header .= "--{$mail_boundary}\r\n";
$header .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$header .= "Date: ".date(R)."\r\n";
$header .= "Content-Transfer-Encoding:7bit\r\n\r\n";
$header .= $message."\r\n\r\n";

// Attach the uploaded files, if there is any.

if($_FILES){

	if (get_magic_quotes_runtime() == 1){
		set_magic_quotes_runtime(0);
	}

	foreach($_FILES as $key=>$value){
		foreach($value as $key2 => $value2){
			$$key2 = $value2;
		}

		if (is_uploaded_file($tmp_name)) {    
			$fp = fopen($tmp_name,'rb');
			$read = fread($fp,$size);
			fclose($fp);

			$file = base64_encode($read);
			$file = chunk_split($file);

			$header .= "--$mail_boundary\r\n";
			$header .= "Content-type: $type; name=\"$name\"\r\n";
			$header .= "Content-Transfer-Encoding:base64\r\n";
			$header .= "Content-Disposition: attachment; filename=\"$name\"\r\n\r\n";
			$header .= $file."\r\n\r\n";
		}
	}
}

// Now, lets deal with what we've got so far!

$valid_email = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email);

if(!$missing && $valid_email) {
	mail($myemail,$subject,'',$header);
} elseif(!$valid_email){
	$thankyou = "Your email address doesnt seem to be valid - please doublecheck it.";
} else {
	if(count($missing)>1){
		$last = array_pop($missing);
		$themissing = implode(', ',$missing).' and '.$last;
		$plu = 's';
	} else {
		$themissing = $missing[0];
	}
	$thankyou = "Sorry, but you do not seem to have filled out the field$plu ".$themissing.". Please go back and fill out all the required fields!";
}


// And, in the very end, we've got to catch the referrers and redirect back to where we came from.

$ref = getenv("HTTP_REFERER");
$ref = explode('?',$ref);
$ref = $ref[0];

$thankyou .= ' Powered by aMAILzing.';

header("Location: $ref?message=$thankyou");


// And then, we're done!

?>
anyone know about phph? cuz i don't !

Thanks in advance
Reply With Quote