I know, that seems odd, but my form doesn’t work UNLESS there is an attachment. I have included the PHP code below; I’m sure there is a simple ‘if attachments = 0 send anyways’ type of code, but the only PHP I’ve learned is from these forums. Thanks in advance for the help.
[code=php]
<?php
ob_start();
$to = ‘[email protected]’;
$name = $_POST[‘RName’];
$email = ‘[email protected]’;
$subject = “Campaign Request”;
$from = $email;
$subject = ‘Campaign Request’;
//$txt = wordwrap($txt,70);
print (‘
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html lang=”en” xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<title>Email</title>
<script type=”text/javascript”>
/*<![CDATA[*/
function progress(){
intWidth = parseInt(document.getElementById(“container1”).style.width) + 1;
if(intWidth <= 400){
document.getElementById(“container1″).style.width = intWidth+”px”;
}else{
document.getElementById(“container1”).style.width = 0;
}
setTimeout(“progress()”,300);
}
/*]]>*/
</script>
</head>
<body>
‘);
// Get html message content
$form_data = “REQUESTED CAMPAIGNS <br>” ;
if(is_array($_POST[‘Campaign’]))
{
foreach($_POST[‘Campaign’] as $value)
{
$form_data .= trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= “<br>” . “<br>” .
‘* REQUESTOR *’ . “<br>” .
‘Name: ‘ . $_REQUEST[‘RName’] . “<br>” .
‘Title: ‘ . $_REQUEST[‘RTitle’] . “<br>” .
‘Email: ‘ . $_REQUEST[‘REmail’] . “@pulte.com” . “<br>” .
‘Phone: ‘ . $_REQUEST[‘RPhone’] . “<br>” .
‘Market: ‘ . $_REQUEST[‘Market’] . “<br>” .
‘Community: ‘ . $_REQUEST[‘Community’] . “<br>” .
‘Start Date: ‘ . $_REQUEST[‘RDate’] . “<br>” ;
if(is_array($_POST[‘AppI’]))
{
foreach($_POST[‘AppI’] as $value)
{
$form_data .= “Approved in: ” . trim(stripslashes($value)) . “<br>” ;
}
}
if(is_array($_POST[‘TCG’]))
{
foreach($_POST[‘TCG’] as $value)
{
$form_data .= “TCG: ” . trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= “<br>” .
‘* DIRECT MAIL *’ . “<br>” .
‘Goal: ‘ . $_REQUEST[‘DM_Goal’] . “<br>” .
‘Qty: ‘ . $_REQUEST[‘DQty’] . “<br>” .
‘Mailing Date: ‘ . $_REQUEST[‘MDate’] . “<br>” .
‘Query Paramaters: ‘ . $_REQUEST[‘DM_Query’] . “<br>” .
‘Template: ‘ . $_REQUEST[‘DMTemplate’] .
‘ ‘ . $_REQUEST[‘If_Other_Type’] . “<br>” .
‘Tagline: ‘ . $_REQUEST[‘Tagline’] . “<br>” ;
if(is_array($_POST[‘DMType’]))
{
foreach($_POST[‘DMType’] as $value)
{
$form_data .= “Type: ” . trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= ‘If Other: ‘ . $_REQUEST[‘If_Other’] . “<br>” .
‘Additional Info: ‘ . $_REQUEST[‘DM_AddInfo’] . “<br>” .
‘RSVP? ‘ . $_REQUEST[‘DM_RSVP’] . “<br>” .
“<br>” . ‘* E-MARKETING *’ . “<br>” .
‘Goal: ‘ . $_REQUEST[‘EM_Goal’] . “<br>” .
‘Subject: ‘ . $_REQUEST[‘EM_Subject’] . “<br>” .
‘Body: ‘ . $_REQUEST[‘EM_Body’] . “<br>” .
‘Landing Page Copy: ‘ . $_REQUEST[‘EM_LCopy’] . “<br>” .
‘Design Ideas: ‘ . $_REQUEST[‘EM_Ideas’] . “<br>” .
‘From: ‘ . $_REQUEST[‘EM_From’] . “<br>” .
‘Legal Approval Received? ‘ . $_REQUEST[‘EM_Legal’] . “<br>” ;
if(is_array($_POST[‘EM_DR’]))
{
foreach($_POST[‘EM_DR’] as $value)
{
$form_data .= “Desired Recipients: ” . trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= ‘Community to Receive: ‘ . $_REQUEST[‘EM_Receive’] . “<br>” .
‘Start: ‘ . $_REQUEST[‘EM_Start’] . “<br>” .
‘RSVP? ‘ . $_REQUEST[‘EM_RSVP’] . “<br>” .
“<br>” . ‘* OUTBOUND *’ . “<br>” .
‘Campaign Name: ‘ . $_REQUEST[‘OB_Name’] . “<br>” .
‘Qty: ‘ . $_REQUEST[‘Call_Quantity’] . “<br>” .
‘Start: ‘ . $_REQUEST[‘OB_SDate’] .
‘ ‘ . $_REQUEST[‘OB_STime’] . “<br>” .
‘End: ‘ . $_REQUEST[‘OB_EDate’] .
‘ ‘ . $_REQUEST[‘OB_ETime’] . “<br>” .
‘Descriptions: ‘ . $_REQUEST[‘OBDes’] . “<br>” .
‘Incentive/Offer: ‘ . $_REQUEST[‘OB_Incentive’] . “<br>” .
‘Impact: ‘ . $_REQUEST[‘Impact’] . “<br>” .
‘Call List Criteria: ‘ . $_REQUEST[‘OB_Criteria’] . “<br>” .
‘Hot Leads: ‘ . $_REQUEST[‘Hot_Leads’] . “<br>” .
‘Special Scripting: ‘ . $_REQUEST[‘SpScrip’] . “<br>” .
‘RSVP? ‘ . $_REQUEST[‘OB_RSVP’] . “<br>” .
“<br>” . ‘* PHONE NUMBER REQUEST *’ . “<br>” ;
if(is_array($_POST[‘PhB’]))
{
foreach($_POST[‘PhB’] as $value)
{
$form_data .= “Brand: ” . trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= ‘Medium: ‘ . $_REQUEST[‘PHMedium’] . ” – ” .
$_REQUEST[‘Medium_Detail’] . “<br>” .
‘Date: ‘ . $_REQUEST[‘PH_Date’] . “<br>” .
‘Additional Info: ‘ . $_REQUEST[‘PH_AddInfo’] . “<br>” .
“<br>” . ‘* SA E-MAIL *’ . “<br>” .
‘Associate: ‘ . $_REQUEST[‘SA_Name’] . “<br>” .
‘Subject: ‘ . $_REQUEST[‘SA_Subject’] . “<br>” .
‘Body: ‘ . $_REQUEST[‘SA_Body’] . “<br>” .
‘Closing: ‘ . $_REQUEST[‘Closing’] . “<br>” .
‘Template: ‘ . $_REQUEST[‘SA_Template’] .
‘ ‘ . $_REQUEST[‘SA_Other’] .”<br>” ;
if(is_array($_POST[‘SA_DR’]))
{
foreach($_POST[‘SA_DR’] as $value)
{
$form_data .= “Desired Recipients: ” . trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= “<br>” . ‘* WEB CAMPAIGN *’ . “<br>” ;
if(is_array($_POST[‘WPB’]))
{
foreach($_POST[‘WPB’] as $value)
{
$form_data .= “Brand: ” . trim(stripslashes($value)) . “<br>” ;
}
}
$form_data .= ‘Template: ‘ . $_REQUEST[‘WPTemplate’] . “<br>” .
‘Start: ‘ . $_REQUEST[‘WP_SDate’] . “<br>” .
‘Teaser Copy: ‘ . $_REQUEST[‘WPTeaser_Copy’] . “<br>” .
‘Design Ideas: ‘ . $_REQUEST[‘WP_Ideas’] . “<br>” .
‘Help required for design? ‘ . $_REQUEST[‘WP_Help’] . “<br>” .
‘Promotion Page URL: ‘ . $_REQUEST[‘WP_URL’] . “<br>” .
‘Promo Page Copy: ‘ . $_REQUEST[‘WP_PCopy’] . “<br>” .
‘Legal Approval Received? ‘ . $_REQUEST[‘WP_Legal’] ;
$message = “<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” n” .
” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”> n” .
“<html xmlns=”http://www.w3.org/1999/xhtml”> n” .
“<head> n” .
” <meta http-equiv=”content-type” content= n” .
” “text/html; charset=iso-8859-1″ /> n” .
“</head> n” .
“<body>$form_data n” .
“</body> n” .
“</html> nn”;
// Obtain file upload vars
$fileatt = $_FILES[‘fileatt’][‘tmp_name’];
$fileatt_type = $_FILES[‘fileatt’][‘type’];
$fileatt_name = $_FILES[‘fileatt’][‘name’];
$headers = “From: $from” ;
if (is_uploaded_file($fileatt)) {
// Read the file to be attached (‘rb’ = read binary)
$file = fopen($fileatt,’rb’);
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = “==Multipart_Boundary_x{$semi_rand}x”;
// Add the headers for a file attachment
$headers .= “nMIME-Version: 1.0n” .
“Content-Type: multipart/mixed;n” .
” boundary=”{$mime_boundary}””;
// Add a multipart boundary above the html message
$message = “This is a multi-part message in MIME format.nn” .
“–{$mime_boundary}n” .
“Content-Type: text/html; charset=”iso-8859-1″n” .
“Content-Transfer-Encoding: 7bitnn” .
$message . “nn”;
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
//We now have everything we need to write the portion of the message that contains the file attachment. Here’s the code:
// Add file attachment to the message
$message .= “–{$mime_boundary}n” .
“Content-Type: {$fileatt_type};n” .
” name=”{$fileatt_name}”n” .
“Content-Disposition: attachment;n” .
” filename=”{$fileatt_name}”n” .
“Content-Transfer-Encoding: base64nn” .
$data . “nn” .
“–{$mime_boundary}–n”;
}else{
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = “==Multipart_Boundary_x{$semi_rand}x”;
// Add the headers for a file attachment
$headers .= “nMIME-Version: 1.0n” .
“Content-Type: multipart/mixed;n” .
” boundary=”{$mime_boundary}””;
// Add a multipart boundary above the html message
$message = “This is a multi-part message in MIME format.nn” .
“–{$mime_boundary}n” .
“Content-Type: text/html; charset=”iso-8859-1″n” .
“Content-Transfer-Encoding: 7bitnn” .
$message . “nn”;
}
//That completes the modifications necessary to accommodate a file attachment. We can now send the message with a quick call to mail:
mail($to, $subject, $message, $headers);
print (‘<h1 id=”content_h1″><a name=”text”> Thank you </a></h1> <p>Your message has been sent.</p>’);
print (‘
</div>
</body>
</html>
‘);
ob_end_flush();
?>