linuxfront-v2-logistics/send_quote.php 📧
A lightweight PHP script that handles “Request a Quote” form submissions on the logistics site. It gathers user input, sanitizes it, constructs an email, and sends it to the customer-service team.
Overview
This file processes POST requests from the quote form.
It:
- Validates that form data exists
- Cleans inputs to prevent header injection
- Builds a plain-text email with quote details
- Sends the email via PHP’s
mail() - Returns a simple success/error response
How It Works
- Entry Point
Checks for any POST data before proceeding. - Data Extraction
Reads form fields: company name, first name, phone, email. - Sanitization
Usesclean_string()to strip dangerous substrings. - Email Assembly
- Defines recipient, subject, and message body
- Compiles each field into the message
- Headers & Send
- Sets
From,Reply-To, andBccheaders - Calls
mail()and suppresses errors with@
- Sets
- Response
- Echoes
"Success"on success - Echoes
"error"on failure
- Echoes
Expected Form Fields
| Field Name | Variable | Description |
|---|---|---|
| companyname | $company_name |
Name of the company |
| firstname | $FirstName |
Requester’s first name |
| PhoneNumber | $PhoneNumber |
Requester’s phone number |
$Email |
Requester’s email address |
Note: Other fields (e.g., ZIP, contact method) are commented out for future use.
Key Components
Data Sanitization
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad, "", $string);
}
- Purpose: Prevent email header injection
- Removes: Common header keywords and HTML links
Email Construction
$email_to = "[email protected]";
$email_subject = "New Quote Details";
$email_message = "Quote details below.\n\n";
$email_message .= "Company Name: " . clean_string($company_name) . "\n";
$email_message .= "First Name: " . clean_string($FirstName) . "\n";
$email_message .= "Phone Number: " . clean_string($PhoneNumber) . "\n";
$email_message .= "Email: " . clean_string($Email) . "\n";
- Builds a simple, human-readable email body
- Newlines (
\n) separate each field
Headers & Sending
$headers = 'From: ' . $Email . "\r\n"
. 'Reply-To: ' . $Email . "\r\n"
. 'Bcc: ' . $bccTo . "\r\n"
. 'X-Mailer: PHP/' . phpversion();
if (@mail($email_to, $email_subject, $email_message, $headers)) {
echo "Success";
// Reset vars (optional)
} else {
echo "error";
}
- Uses the requester’s email as the sender
- Attempts blind-carbon-copy to a
$bccTo(currently commented/unset) - Suppresses warnings with
@
Integration & Usage
- Called by: Quote & Ship form via POST (possibly AJAX)
- Response: Plain-text
"Success"or"error"for UI feedback - No external libraries: Relies solely on PHP core
Potential Improvements ⚙️
- 🔒 Input Validation: Ensure required fields are non-empty & valid
- 📡 SMTP Configuration: Use a mailer library (e.g., PHPMailer) for reliability
- 🐞 Fix Undefined
$bccTo: Define or remove BCC header - 🔄 CSRF Protection: Add tokens to prevent cross-site forgery
- 📥 Logging: Record email outcomes for auditing
Related Files & Patterns
- A more comprehensive version exists at
linuxfront-v2/send_quote.phphandling additional fields (street, weight, etc.) - Likely paired with a front-end form (e.g.,
start_quote.php) that directs submissions here - Follows a common “clean + build + mail” pattern used elsewhere in the codebase
send_quote.php provides a quick, no-frills way to capture quote requests and forward them to customer service, fitting the marketing pages’ needs for instant email notifications.