Hi guys! New to the community and hope to learn a lot here!
Here is some background info and what I want to do, and what I know.
I have been building websites for years, and I am familiar with Actionscript 3.0. And I have successful ran a few wordpress websites. What I am trying to do right now however is modify this form script I found, to only email the data when the field isn’t left blank. It’s stumping me because the actual “message” that ends up being the body of the email is a variable. And form what I can tell I can’t figure out how to put if statements into it. If anyone can take a look at this script and give me any pointers you would be awesome.
[code]<?php
//trying to store the date in a separate variable only when it’s not blank
if ($_POST[‘starttime’] == ‘’) {
//nothing;
}
else
{
$showStartTime == "Start time: " . $_POST[‘starttime’] . “”;
}
if ($_POST[‘finishtime’] == ‘’)
{
//nothing;
}
else
{
$showFinishTime == "Finish time: " . $_POST[‘finishtime’] . “”;
}
// Read POST request params into global vars
$to = $_POST[‘to’];
$from = $_POST[‘from’];
$name = $_POST[‘name’];
$company = $_POST[‘company’];
$newcustomer = $_POST[‘newcustomer’];
$address1 = $_POST[‘address1’];
$address2 = $_POST[‘address2’];
$subject = ("Event Rental for " . $name . “”);
$description = $_POST[‘description’];
$phone = $_POST[‘phone’];
$message = ("
Name: " . $name . "
Company or Organization: " . $company . "
Phone Number: " . $phone . "
Email Address: " . $from . "
Street Address: " . $address1 . " " . $address2 . "
New Customer: " . $newcustomer . "
Customer From: " . $_POST[‘howyouheard’] . "
Interested in: SkyLoft " . $_POST[‘whichspace’] . "
Date: " . $_POST[‘date’] . "
Day of Week: " . $_POST[‘dayofweek’] . "
" . $showStartTime . "
" . $showFinishTime . "
Number of Guests: " . $_POST[‘Guests’] . "
Format: " . $_POST[‘format’] . "
Occasion: " . $_POST[‘Occasion’] . "
Optional Needs: " . $_POST[‘dj’] . " " . $_POST[‘tables’] . " " . $_POST[‘chairs’] . " " . $_POST[‘eventbanner’] . " " . $_POST[‘pasoundsystem’] . "
Message:
" . $description . "
");
// 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.0\n” .
“Content-Type: multipart/mixed;\n” .
" boundary="{$mime_boundary}"";
// Add a multipart boundary above the plain message
$message = “This is a multi-part message in MIME format.\n\n” .
“–{$mime_boundary}\n” .
“Content-Type: text/plain; charset=“iso-8859-1”\n” .
“Content-Transfer-Encoding: 7bit\n\n” .
$message . “\n\n”;
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// 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: base64\n\n” .
$data . “\n\n” .
“–{$mime_boundary}–\n”;
}
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo “
Thank you for your interest in SkyLofts!
You should recieve a verification in your inbox that we recieved your request. We will contact you as soon as possible and hopefully be able to answer any questions you may have! You can also contact us via phone 410-791-6699, or toll-free 1-800-344-0410.
} else {
echo “
There was an error when processing your request. Please try again.
”;}
?>[/code]