PHP form - Upload/E-mail Attachment problem
01-18-2008, 09:53 AM
|
PHP form - Upload/E-mail Attachment problem
|
Posts: 17
Name: Matt
|
I am trying to get my web form to enable the user to attach files to the form and be received in my email. I tried working the code to do this but just can't get it right. This form works fine, except when I receive the confirmation email it does not attach the files that are browsed. Am I doing something wrong? (I think my html might be what's incorrect, it could be a really simple fix)
Here is a link to the form:
www.audio-logic.net/register.html
(Can you please also help to let me know why the form is so spaced out. It does not look like this in Dreamweaver and I couldn't figure out what was causing this)
Here is the php file:
PHP Code:
<?PHP
DEFINE('kOptional', true); DEFINE('kMandatory', false);
error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('track_errors', true);
function DoStripSlashes($FieldValue) { if ( get_magic_quotes_gpc() ) { if (is_array($FieldValue) ) { return array_map('DoStripSlashes', $FieldValue); } else { return stripslashes($FieldValue); } } else { return $FieldValue; } }
#---------- # FilterCChars:
function FilterCChars($TheString) { return preg_replace('/[\x00-\x1F]/', '', $TheString); }
#---------- # Validate: Email
function check_email($email, $optional) { if ( (strlen($email) == 0) && ($optional === kOptional) ) { 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']; }
$FTGrealname = DoStripSlashes( $_REQUEST['realname'] ); $FTGemail = DoStripSlashes( $_REQUEST['email'] ); $FTGPositionTitle = DoStripSlashes( $_REQUEST['PositionTitle'] ); $FTGCompany = DoStripSlashes( $_REQUEST['Company'] ); $FTGCompany2 = DoStripSlashes( $_REQUEST['Company2'] ); $FTGAddress = DoStripSlashes( $_REQUEST['Address'] ); $FTGCity = DoStripSlashes( $_REQUEST['City'] ); $FTGState = DoStripSlashes( $_REQUEST['State'] ); $FTGPhone = DoStripSlashes( $_REQUEST['Phone'] ); $FTGMobile = DoStripSlashes( $_REQUEST['Mobile'] ); $FTGFax = DoStripSlashes( $_REQUEST['Fax'] ); $FTGReference = DoStripSlashes( $_REQUEST['Reference'] ); $FTGProjectType = DoStripSlashes( $_REQUEST['ProjectType'] ); $FTGCurrentDomain = DoStripSlashes( $_REQUEST['CurrentDomain'] ); $FTGDomainDesired1 = DoStripSlashes( $_REQUEST['DomainDesired1'] ); $FTGDomainDesired2 = DoStripSlashes( $_REQUEST['DomainDesired2'] ); $FTGDomainDesired3 = DoStripSlashes( $_REQUEST['DomainDesired3'] ); $FTGBudget = DoStripSlashes( $_REQUEST['Budget'] ); $FTGCompletionDate = DoStripSlashes( $_REQUEST['CompletionDate'] ); $FTGGoals = DoStripSlashes( $_REQUEST['Goals'] ); $FTGPagetypes = DoStripSlashes( $_REQUEST['Pagetypes'] ); $FTGcustomerpage1 = $_FILES['customerpage1']['name']; $FTGcustomerpage2 = $_FILES['customerpage2']['name']; $FTGcustomerpage3 = $_FILES['customerpage3']['name']; $FTGcustomerpage4 = $_FILES['customerpage4']['name']; $FTGcustomerpage5 = $_FILES['customerpage5']['name']; $FTGcustomerpage6 = $_FILES['customerpage6']['name']; $FTGcustomerpage7 = $_FILES['customerpage7']['name']; $FTGcustomerpage8 = $_FILES['customerpage8']['name']; $FTGCompetitor1 = DoStripSlashes( $_REQUEST['Competitor1'] ); $FTGCompetitor2 = DoStripSlashes( $_REQUEST['Competitor2'] ); $FTGCompetitor3 = DoStripSlashes( $_REQUEST['Competitor3'] ); $FTGCompetitor4 = DoStripSlashes( $_REQUEST['Competitor4'] ); $FTGLogo = DoStripSlashes( $_REQUEST['Logo'] ); $FTGLogoSubmission = DoStripSlashes( $_REQUEST['LogoSubmission'] ); $FTGAdditionalComments = DoStripSlashes( $_REQUEST['AdditionalComments'] ); $FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );
# Fields Validations
$ValidationFailed = false;
if (!check_email($FTGemail, kMandatory)) { $ValidationFailed = true; $FTGemail_errmsg = 'Please enter a valid email address'; $ErrorList .= $FTGemail_errmsg . '<br/>'; }
# Include message in error page and dump it to the browser
if ($ValidationFailed === true) {
$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';
$ErrorPage = str_replace('<!--VALIDATIONERROR-->', $ErrorList, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:realname-->', $FTGrealname, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:email-->', $FTGemail, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:PositionTitle-->', $FTGPositionTitle, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Company-->', $FTGCompany, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Company2-->', $FTGCompany2, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Address-->', $FTGAddress, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:City-->', $FTGCity, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:State-->', $FTGState, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Phone-->', $FTGPhone, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Mobile-->', $FTGMobile, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Fax-->', $FTGFax, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Reference-->', $FTGReference, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:ProjectType-->', $FTGProjectType, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:CurrentDomain-->', $FTGCurrentDomain, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:DomainDesired1-->', $FTGDomainDesired1, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:DomainDesired2-->', $FTGDomainDesired2, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:DomainDesired3-->', $FTGDomainDesired3, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Budget-->', $FTGBudget, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:CompletionDate-->', $FTGCompletionDate, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Goals-->', $FTGGoals, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Pagetypes-->', $FTGPagetypes, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage1-->', $FTGcustomerpage1, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage2-->', $FTGcustomerpage2, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage3-->', $FTGcustomerpage3, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage4-->', $FTGcustomerpage4, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage5-->', $FTGcustomerpage5, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage6-->', $FTGcustomerpage6, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage7-->', $FTGcustomerpage7, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:customerpage8-->', $FTGcustomerpage8, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Competitor1-->', $FTGCompetitor1, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Competitor2-->', $FTGCompetitor2, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Competitor3-->', $FTGCompetitor3, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Competitor4-->', $FTGCompetitor4, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Logo-->', $FTGLogo, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:LogoSubmission-->', $FTGLogoSubmission, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:AdditionalComments-->', $FTGAdditionalComments, $ErrorPage); $ErrorPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $ErrorPage); $ErrorPage = str_replace('<!--ERRORMSG:email-->', $FTGemail_errmsg, $ErrorPage);
echo $ErrorPage; exit;
} # Email to Form Owner
$emailSubject = FilterCChars("New Customer Registration");
$emailBody = "--FTG_BOUNDRY\n" . "Content-Type: text/plain; charset=\"ISO-8859-1\"\n" . "Content-Transfer-Encoding: 8bit\n" . "\n" . "New Customer: $FTGrealname\n" . "\n" . "Customer Information:\n" . "\n" . "email : $FTGemail\n" . "PositionTitle : $FTGPositionTitle\n" . "Company : $FTGCompany\n" . "Company2 : $FTGCompany2\n" . "Address : $FTGAddress\n" . "City : $FTGCity\n" . "State : $FTGState\n" . "Phone : $FTGPhone\n" . "Mobile : $FTGMobile\n" . "Fax : $FTGFax\n" . "Reference : $FTGReference\n" . "\n" . "Website Information:\n" . "\n" . "ProjectType : $FTGProjectType\n" . "CurrentDomain : $FTGCurrentDomain\n" . "DomainDesired1 : $FTGDomainDesired1\n" . "DomainDesired2 : $FTGDomainDesired2\n" . "DomainDesired3 : $FTGDomainDesired3\n" . "Budget : $FTGBudget\n" . "CompletionDate : $FTGCompletionDate\n" . "Goals : $FTGGoals\n" . "Pagetypes : $FTGPagetypes\n" . "customerpage1 : $FTGcustomerpage1\n" . "customerpage2 : $FTGcustomerpage2\n" . "customerpage3 : $FTGcustomerpage3\n" . "customerpage4 : $FTGcustomerpage4\n" . "customerpage5 : $FTGcustomerpage5\n" . "customerpage6 : $FTGcustomerpage6\n" . "customerpage7 : $FTGcustomerpage7\n" . "customerpage8 : $FTGcustomerpage8\n" . "Competitor1 : $FTGCompetitor1\n" . "Competitor2 : $FTGCompetitor2\n" . "Competitor3 : $FTGCompetitor3\n" . "Competitor4 : $FTGCompetitor4\n" . "Logo : $FTGLogo\n" . "LogoSubmission : $FTGLogoSubmission\n" . "AdditionalComments : $FTGAdditionalComments\n" . "Submit : $FTGSubmit\n" . "" . "\n";
if ( is_uploaded_file($_FILES['customerpage1']['tmp_name']) ) {
$fileName = $_FILES['customerpage1']['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['customerpage1']['type'] . "; name=\"" . $_FILES['customerpage1']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage2']['tmp_name']) ) {
$fileName = $_FILES['customerpage2']['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['customerpage2']['type'] . "; name=\"" . $_FILES['customerpage2']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage3']['tmp_name']) ) {
$fileName = $_FILES['customerpage3']['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['customerpage3']['type'] . "; name=\"" . $_FILES['customerpage3']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage4']['tmp_name']) ) {
$fileName = $_FILES['customerpage4']['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['customerpage4']['type'] . "; name=\"" . $_FILES['customerpage4']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage5']['tmp_name']) ) {
$fileName = $_FILES['customerpage5']['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['customerpage5']['type'] . "; name=\"" . $_FILES['customerpage5']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage6']['tmp_name']) ) {
$fileName = $_FILES['customerpage6']['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['customerpage6']['type'] . "; name=\"" . $_FILES['customerpage6']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage7']['tmp_name']) ) {
$fileName = $_FILES['customerpage7']['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['customerpage7']['type'] . "; name=\"" . $_FILES['customerpage7']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
if ( is_uploaded_file($_FILES['customerpage8']['tmp_name']) ) {
$fileName = $_FILES['customerpage8']['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['customerpage8']['type'] . "; name=\"" . $_FILES['customerpage8']['name'] . "\"\n" . "Content-disposition: attachment\n" . "Content-transfer-encoding: base64\n" . "\n" . "$fileAttach\n" . "\n"; }
$emailBody .= "--FTG_BOUNDRY--\n"; $emailTo = 'Audiologic <mattrobertcannon@gmail.com>'; $emailFrom = FilterCChars("specialsauce311@gmail.com"); $emailHeader = "From: $emailFrom\n" . "MIME-Version: 1.0\n" . "Content-Type: multipart/mixed; boundary=\"FTG_BOUNDRY\"\n" . "This is a multi-part Content MIME format.\n"; mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Include message in the success page and dump it to the browser
$SuccessPage = '<html><head><title>Success</title></head><body>Thank you for registering with audio-logic.net, you will receive an email shortly with instructions on how to get started.</body></html>';
$SuccessPage = str_replace('<!--FIELDVALUE:realname-->', $FTGrealname, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:email-->', $FTGemail, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:PositionTitle-->', $FTGPositionTitle, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Company-->', $FTGCompany, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Company2-->', $FTGCompany2, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Address-->', $FTGAddress, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:City-->', $FTGCity, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:State-->', $FTGState, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Phone-->', $FTGPhone, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Mobile-->', $FTGMobile, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Fax-->', $FTGFax, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Reference-->', $FTGReference, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:ProjectType-->', $FTGProjectType, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:CurrentDomain-->', $FTGCurrentDomain, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:DomainDesired1-->', $FTGDomainDesired1, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:DomainDesired2-->', $FTGDomainDesired2, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:DomainDesired3-->', $FTGDomainDesired3, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Budget-->', $FTGBudget, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:CompletionDate-->', $FTGCompletionDate, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Goals-->', $FTGGoals, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Pagetypes-->', $FTGPagetypes, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage1-->', $FTGcustomerpage1, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage2-->', $FTGcustomerpage2, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage3-->', $FTGcustomerpage3, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage4-->', $FTGcustomerpage4, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage5-->', $FTGcustomerpage5, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage6-->', $FTGcustomerpage6, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage7-->', $FTGcustomerpage7, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:customerpage8-->', $FTGcustomerpage8, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Competitor1-->', $FTGCompetitor1, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Competitor2-->', $FTGCompetitor2, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Competitor3-->', $FTGCompetitor3, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Competitor4-->', $FTGCompetitor4, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Logo-->', $FTGLogo, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:LogoSubmission-->', $FTGLogoSubmission, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:AdditionalComments-->', $FTGAdditionalComments, $SuccessPage); $SuccessPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $SuccessPage);
echo $SuccessPage; exit; ?>
|
|
|
|
01-18-2008, 10:02 AM
|
Re: PHP form - Upload/E-mail Attachment problem
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Just a quick guess, but I'm seeing "FTG_BOUNDRY".
Isn't it rather "FTG_BOUNDARY" ?
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
01-18-2008, 10:12 AM
|
Re: PHP form - Upload/E-mail Attachment problem
|
Posts: 17
Name: Matt
|
I made the change. Form still works, still no attachements
Could it have something to do with the way I have the browse.
Do I need any upload button also?
|
|
|
|
01-18-2008, 08:43 PM
|
Re: PHP form - Upload/E-mail Attachment problem
|
Posts: 83
Name: Colin
Location: USA
|
I am just guessing you might have overlooked the "multipart/form-data" portion of the form tag.
Quote:
|
Originally Posted by W3C
The value "multipart/form-data" should be used in combination with the INPUT element, type="file".
|
http://www.w3.org/TR/html4/interact/forms.html#h-17.3
__________________
Please login or register to view this content. Registration is FREE | Freelance PHP solutions for small to midsized projects | Please login or register to view this content. Registration is FREE
|
|
|
|
|
« Reply to PHP form - Upload/E-mail Attachment problem
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|