Need help attaching a file in my PHP form...

Hello

I am using the PHP environment that crystaltech installed. I read your PHP FormMail Script zip file but do not see any thing about attaching a file into a PHP form that is mailed.

Below is a copy of my PHP code. The location is http://www.ammany.org/program-guide/2006/program-guide-form.html the php file is program-guide-form.php

The code below decodes the attachment. On other hosts I have no problem with the code so I thought there may be something unique about your code. Any insight would be greatly appreciated.

Thank you for your assistance.
Dora

<?PHP

error_reporting(7);

#----------
# Validate: String

function check_string($value, $low, $high, $mode, $optional)
{
if ( (strlen($value) == 0) && ($optional === true) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == 1) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == 2) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == 3) ) {
return true;
} else {
return false;
}
}
#----------
# Validate: Email

function check_email($email, $optional)
{
if ( (strlen($email) == 0) && ($optional === true) ) {
return true;
} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
return true;
} else {
return false;
}
}

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}

# RegisterGlobals OFF

$FTGyourname = $_POST['yourname'];
$FTGeMail = $_POST['eMail'];
$FTGPhone = $_POST['Phone'];
$FTGadrepName = $_POST['adrepName'];
$FTGNameBusinessIndividualFamily = $_POST['NameBusinessIndividualFamily'];
$FTGaddress1 = $_POST['address1'];
$FTGaddress2 = $_POST['address2'];
$FTGcity = $_POST['city'];
$FTGstate = $_POST['state'];
$FTGzipcode = $_POST['zipcode'];
$FTGwebsite = $_POST['website'];
$FTGradiobutton = $_POST['radiobutton'];
$FTGadcopy = $_POST['adcopy'];
$FTGcheckbox = $_POST['checkbox'];
$FTGattachfile = $_FILES['attachfile']['name'];
$FTGSubmit = $_POST['Submit'];

if (get_magic_quotes_gpc) {
$FTGyourname = stripslashes($FTGyourname);
$FTGeMail = stripslashes($FTGeMail);
$FTGPhone = stripslashes($FTGPhone);
$FTGadrepName = stripslashes($FTGadrepName);
$FTGNameBusinessIndividualFamily = stripslashes($FTGNameBusinessIndividualFamily);
$FTGaddress1 = stripslashes($FTGaddress1);
$FTGaddress2 = stripslashes($FTGaddress2);
$FTGcity = stripslashes($FTGcity);
$FTGstate = stripslashes($FTGstate);
$FTGzipcode = stripslashes($FTGzipcode);
$FTGwebsite = stripslashes($FTGwebsite);
$FTGradiobutton = stripslashes($FTGradiobutton);
$FTGadcopy = stripslashes($FTGadcopy);
$FTGcheckbox = stripslashes($FTGcheckbox);
$FTGSubmit = stripslashes($FTGSubmit);
}
# Fields Validations

$validationFailed = false;

if ( (! check_string($FTGyourname, 1, 0, 1, true))) {
$validationFailed = true;
}

if ( (! check_email($FTGeMail, true))) {
$validationFailed = true;
}

if ( (! check_string($FTGPhone, 1, 0, 1, true))) {
$validationFailed = true;
}

if ( (! check_string($FTGradiobutton, 1, 0, 1, true))) {
$validationFailed = true;
}

if ( (! check_string($FTGadcopy, 1, 0, 1, true))) {
$validationFailed = true;
}

# Redirect user to the error page

if ($validationFailed == true) {

header("Location: error.html");
exit;

}

# Email to Form Owner

$emailTo = '"Amma Program Guide Design - Ad Submitted" ,"Amma Program Guide Webmaster - Ad Sumbitted" ';

$emailSubject = "Ad Submitted for Amma Program Guide";
$emailSubject = preg_replace('/[\x00-\x1F]/', '', $emailSubject);

$emailFrom = "$FTGeMail";
$emailFrom = preg_replace('/[\x00-\x1F]/', '', $emailFrom);

$emailHeader = "From: $emailFrom\n"
. "Reply-To: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-Type: multipart/mixed; boundary=\"FTG_BOUNDRY\"\n"
. "X-Sender: $emailFrom\n"
. "X-Mailer: PHP\n"
. "X-Priority: 3\n"
. "Return-Path: $emailFrom\n"
. "This is a multi-part Content MIME format.\n";

$emailBody = "--FTG_BOUNDRY\n"
. "Content-Type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-Transfer-Encoding: quoted-printable\n"
. "\n"
. "yourname: $FTGyourname\n"
. "eMail: $FTGeMail\n"
. "Phone: $FTGPhone\n"
. "adrepName: $FTGadrepName\n"
. "NameBusinessIndividualFamily: $FTGNameBusinessIndividualFamily\n"
. "address1: $FTGaddress1\n"
. "address2: $FTGaddress2\n"
. "city: $FTGcity\n"
. "state: $FTGstate\n"
. "zipcode: $FTGzipcode\n"
. "website: $FTGwebsite\n"
. "radiobutton: $FTGradiobutton\n"
. "adcopy: $FTGadcopy\n"
. "checkbox: $FTGcheckbox\n"
. "attachfile: $FTGattachfile\n"
. "Submit: $FTGSubmit\n"
. "\n"
. ""
. "\n";

/* Specify your SMTP Server, Port and Valid From Address */
ini_set("SMTP","mail.ammany.org");
ini_set("smtp_port","25");
ini_set("sendmail_from","addesign@ammany.org");

if (file_exists($_FILES['attachfile']['tmp_name']) === true) {

$fileName = $_FILES['attachfile']['tmp_name'];
$fileHandle = fopen($fileName, 'r');
$fileAttach = fread($fileHandle, filesize ($fileName));
fclose($fileHandle);

$fileAttach = chunk_split(base64_encode($fileAttach));

$emailBody .= "--FTG_BOUNDRY\n"
. "Content-Type: " . $_FILES['attachfile']['type'] . "; name=\"" . $_FILES['attachfile']['name'] . "\"\n"
. "Content-disposition: attachment\n"
. "Content-transfer-encoding: base64\n"
. "\n"
. "$fileAttach\n"
. "\n";

}

$emailBody .= "--FTG_BOUNDRY--\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

# Confirmation Email to User

$confEmailTo = $FTGeMail;
$confEmailTo = preg_replace('/[\x00-\x1F]/', '', $confEmailTo);

$confEmailSubject = "Thank you for submitting your ad";
$confEmailSubject = preg_replace('/[\x00-\x1F]/', '', $confEmailSubject);

$confEmailBody = "yourname: $FTGyourname\n"
. "eMail: $FTGeMail\n"
. "Phone: $FTGPhone\n"
. "adrepName: $FTGadrepName\n"
. "NameBusinessIndividualFamily: $FTGNameBusinessIndividualFamily\n"
. "address1: $FTGaddress1\n"
. "address2: $FTGaddress2\n"
. "city: $FTGcity\n"
. "state: $FTGstate\n"
. "zipcode: $FTGzipcode\n"
. "website: $FTGwebsite\n"
. "radiobutton: $FTGradiobutton\n"
. "adcopy: $FTGadcopy\n"
. "checkbox: $FTGcheckbox\n"
. "attachfile: $FTGattachfile\n"
. "Submit: $FTGSubmit\n"
. "";

$confEmailHeader = "From: eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%61%64%64%65%73%69%67%6e%40%61%6d%6d%61%6e%79%2e%6f%72%67%22%3e%61%64%64%65%73%69%67%6e%40%61%6d%6d%61%6e%79%2e%6f%72%67%3c%2f%61%3e%27%29%3b'))\n"
. "Reply-To: eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%61%64%64%65%73%69%67%6e%40%61%6d%6d%61%6e%79%2e%6f%72%67%22%3e%61%64%64%65%73%69%67%6e%40%61%6d%6d%61%6e%79%2e%6f%72%67%3c%2f%61%3e%27%29%3b'))\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: quoted-printable\n";

mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);

# Redirect user to success page

header("Location: success.html");
exit;

# End of PHP script
?>

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Foound it!....

I had \n and when I added \r\n the attachment appeared.

Now I am looking for field validation code.

User login