I am new with PHP and I love it... I made my first form today a really big one...everything works great so I can make my other 8 forms... but then I thought it would be great if the visitor could attach images along with the form... here is my code...
<?php
// list all vars to be expected from the movie
$vars = array("name", "title", "company", "address", "city", "telephone", "fax", "email", "aoutdiam", "aoutdiaminch", "boutdiam", "boutdiaminch", "boutdiamp", "boutdiampinch", "coutdiam", "coutdiaminch", "aindiam", "aindiaminch", "bindiam", "bindiaminch", "bindiamp", "bindiampinch", "cindiam", "cindiaminch", "load1", "load1lbs", "load1p", "load1plbs", "load1at", "load1atlbs", "load2", "load2lbs", "load2p", "load2plbs", "load2at", "load2atlbs", "rate", "ratelbs", "ratep", "rateplbs", "ratebetween", "ratebetweeninch", "ratebetweenand", "ratebetweenandinch", "maxextlength", "maxextlengthinch", "relativeloop", "dirwind", "type", "alengthmax", "alengthmaxinch", "alengthmin", "alengthmininch", "blength", "blengthinch", "blengthp", "blengthpinch", "clength", "clengthinch", "wirediam", "wirediaminch", "coildiam", "coildiaminch", "activecoils", "bodylength", "bodylengthinch", "initialtension", "initialtensionlbs", "quanityquote", "typematerial", "othertypematerial", "finish", "operatingtemp", "operatingtemptype", "enduse", "other", "file1");
// and import them into the script
foreach($vars as $var)
if(isset($POST[$var]))
$$var = $POST[$var];
else
$$var = '';
// check variables
if(strlen($name) < 1)
die("Please Click your Browser's Back button and Enter a Name");
if(strlen($company) < 1)
die("Please Click your Browser's Back button and Enter a Company");
if(strlen($address) < 1)
die("Please Click your Browser's Back button and Enter an Address");
if(strlen($city) < 1)
die("Please Click your Browser's Back button and Enter City, Zip, and State");
if(strlen($telephone) < 7)
die("Please Click your Browser's Back button and Enter a Telephone Number");
if(strlen($fax) < 7)
die("Please Click your Browser's Back button and Enter a Fax Number");
if(strlen($aoutdiam) < 1 and strlen($aindiam) < 1)
die("Please Click your Browser's Back button and Enter an Outside or Inside Diameter");
if(strlen($alengthmax) < 1 and strlen($blength) < 1)
die("Please Click your Browser's Back button and Enter a value for Length Inside Ends");
if(strlen($wirediam) < 1)
die("Please Click your Browser's Back button Enter a Wire Diameter");
if(strlen($type) < 1)
die("Please Click your Browser's Back button Enter Loop or Hook Type");
if(strlen($bodylength) < 1)
die("Please Click your Browser's Back button Enter Body Length");
if(strlen($initialtension) < 1)
die("Please Click your Browser's Back button Enter Initial Tension");
if(strlen($typematerial) < 1 and strlen($othertypematerial) < 1)
die("Please Click your Browser's Back button and Enter a value for Length Inside Ends");
// where to send it
// remove or configure one of the two code blocks
// otherwise your mail will be sent to johnnybegood@hotmail.com 🙂
//* this one for the selectable recipients
$recips = array("support" => "support@somesite.com", "account" => "billing@somesite.com");
$recip = $recips[$recip];
// if something went wrong, send to default address
if(empty($recip)) $recip = "support@somesite.com";
// * end selectable recipient *****
// ** or one fixed recipient
$recip = "spettye@houston.rr.com";
// end fixed recipient ******
// build up message
// this code for any multiline text fields
$message = str_replace("\r", "\n", $message);
// info vars
$sender = $_SERVER[REMOTE_ADDR];
// you can rearrange this - just do not add or remove quotes
$email_message = "RFQ Sent by
Name: $name
Title: $title
Company: $company
Address: $address
City, State, and Zip: $city
Telephone: $telephone
Fax: $fax
Email: $email
Outside Diameter
a. $aoutdiam $aoutdiaminch
b. $boutdiam $boutdiaminch +/- $boutdiamp $boutdiampinch
c. work in $coutdiam $coutdiaminch
Inside Diameter
a. $aindiam $aindiaminch
b. $bindiam $bindiaminch +/- $bindiamp $bindiampinch
c. work over $cindiam $cindiaminch
Load 1 $load1 $load1lbs +/- $load1p $load1plbs
@ $load1at $load1atlbs
Load 2 $load2 $load2lbs +/- $load2p $load2plbs
@ $load2at $load2atlbs
Rate: $rate $ratelbs +/- $ratep $rateplbs
between lengths of $ratebetween $ratebetweeninch and $ratebetweenand $ratebetweenandinch
Max. extended length (inside ends) without set: $maxextlength $maxextlengthinch
Relative loop position, $relativeloop degrees maximum, seperation of loop planes
Direction of wind: $dirwind
Loop or Hook type: $type
Advisory Data
Length inside ends:
a. $alengthmax $alengthmaxinch max., $alengthmin $alengthmininch min. or
b. $blength $blengthinch +/- $blengthp $blengthpinch
c. approx. $clength $clengthinch
Wire Diameter: $wirediam $wirediaminch
Mean Coil Diameter: $coildiam $coildiaminch
Number of Active Coils: $activecoils
Body Length: $bodylength $bodylengthinch
Initial Tension: $initialtension $initialtensionlbs
Special Information
Quanity to Quote: $quanityquote
Type of Material: $typematerial $othertypematerial
Finish: $finish
Operating Temperature: $operatingtemp $operatingtemptype
End Use or Application:
$enduse
- Other:
$other
Sender's IP Address: $sender";
//copy($file1, $file1_name);
$fileatt=$file1;
$fileatt_type=$file1_type;
$fileatt_name=$file1;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$headers = "From: [email]RFQ@CoilingTech.com[/email]";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
$email_message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" ."--{$mime_boundary}--\n";
mail($recip, "RFQ", $email_message, $headers);
// send it off
// note - if you omit the last part, a few servers do not send mail at all,
// but most would show strange senders like nobody@server17.hostingcompany.com
//mail($recip, "RFQ for Extension Springs", $mailbody, "From: RFQ Form from Web Site");
// if($chked==0) unlink($file1_name);
// and tell visitor
print "Request for Quote has been sent! We will be contacting you shortly. Please Close this Window to Return to CoilingTech.com";
?>
Email goes through like a champ but with no attachment... I get this error msg.
Warning: fread(): supplied argument is not a valid stream resource in /home/httpd/vhosts/thecarsongroup.net/httpdocs/rfq2.php on line 141
Warning: fclose(): supplied argument is not a valid stream resource in /home/httpd/vhosts/thecarsongroup.net/httpdocs/rfq2.php on line 142
Request for Quote has been sent! We will be contacting you shortly. Please Close this Window to Return to CoilingTech.com
Any Help?????