I am having a problem where the PHP script sends the collected data fields as an attachment (array.htm) and the main message is blank. So no attachment and a blank message. Can you assist me?
<?php
// Email recipient & email subject
$to = "webmaster@webmaster.com";
$subject = 'This is a test';
// Collected parameters
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST ['telephone'];
$address = $_POST ['address'];
$postcode = $_POST ['postcode'];
$type = $_POST ['type'];
$description = $_POST['description'];
$attachments = $_FILES ['file'];
$path = $_SERVER['DOCUMENT_ROOT'];
if (!empty($_FILES['attachment']['tmp_name'])) {
$path = $_FILES['attachment']['name'];
if (copy($_FILES['attachment']['tmp_name'], $path)) $attachments = $path;
}
//PHP variables
$headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Disposition: attachment; filename = \"" . $attachments . "\"\n\n";
//Printed parameters
$message = '<table width="100%" cellspacing="0" cellpadding="5" border="0">';
$message .= '<tr><td width="150px"><b>Business Name:</b></td><td>' . $name . '</td></tr>';
$message .= '<tr><td width="150px"><b>Email:</b></td><td>' . $email . '</td></tr>';
$message .= '<tr><td width="150px"><b>Telephone:</b></td><td>' . $telephone . '</td></tr>';
$message .= '<tr><td width="150px"><b>Address:</b></td><td>' . $address . '</td></tr>';
$message .= '<tr><td width="150px"><b>Postcode:</b></td><td>' . $postcode . '</td></tr>';
$message .= '<tr><td width="150px"><b>Business Type:</b></td><td>' . $type . '</td></tr>';
$message .= '<tr><td width="150px"><b>Description:</b></td><td>' . $description . '</td></tr>';
$message .= '</table>';
// Send mail
mail($to, $subject, $message, $headers);
// Redirect success
$theResults = header("Location: \success.html");
exit;
?>
UPDATE I changed the parameter 'attachment' to 'file' and now I get a correctly labelled attachment as per the file included in the form but the attachment still contains the form information text so it is not a true jpg as was attached originally and of course the message is still blank. BUT now I get the proper file attachment uploaded to the area of the server where the script runs. Does this help?
<?php
// Email recipient & email subject
$to = "webmaster@webmaster.com";
$subject = 'This is a test';
// Collected parameters
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$type = $_POST['type'];
$description = $_POST['description'];
$file = $_FILES['file'];
$path = $_SERVER['DOCUMENT_ROOT'];
if (!empty($_FILES['file']['tmp_name'])) {
$path = $_FILES['file']['name'];
if (copy($_FILES['file']['tmp_name'], $path)) $file = $path;
}
//PHP variables
$headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Disposition: attachment; filename = \"" . $file . "\"\n\n";
//Printed parameters
$message = '<table width="100%" cellspacing="0" cellpadding="5" border="0">';
$message .= '<tr><td width="150px"><b>Business Name:</b></td><td>' . $name . '</td></tr>';
$message .= '<tr><td width="150px"><b>Email:</b></td><td>' . $email . '</td></tr>';
$message .= '<tr><td width="150px"><b>Telephone:</b></td><td>' . $telephone . '</td></tr>';
$message .= '<tr><td width="150px"><b>Address:</b></td><td>' . $address . '</td></tr>';
$message .= '<tr><td width="150px"><b>Postcode:</b></td><td>' . $postcode . '</td></tr>';
$message .= '<tr><td width="150px"><b>Business Type:</b></td><td>' . $type . '</td></tr>';
$message .= '<tr><td width="150px"><b>Description:</b></td><td>' . $description . '</td></tr>';
$message .= '</table>';
// Send mail
mail($to, $subject, $message, $headers);
// Redirect success
$theResults = header("Location: \success.html");
exit;
?>