Hi,
I'm pretty rubbish at this and really new. I made a form for a friends website some time ago and the hosting company has changed some settings and now his form doesn't work. I asked the hosting company what the problem is and received this reply:
"Since your code was developed there have been some changes to the PHP security layer used (suhosin) as a result of new PHP vunerabilities, which prevent the use of blank lines (\n\n) within the headers passed to the mail() function. New lines have never been permissable within email message headers (only at the very end), however this wasn't enforced historically. Although it worked previously, the email being generated wasn't strictly speaking valid.
The solution to Melanie's email problem is to remove all instances of "\n\n" within your $header variable, and replace these with "\n".
Having looked at your code however, this will not be quite as straight forward as you have included the MIME parts within the $header, and the MIME parts require the use of \n\n. MIME parts are not header elements, they are officially part of the message body, so these should be moved into your $message variable where use of \n\n will be allowed"
I've tried doing this myself but I mess it up every time and my mate is starting to lose a bit of business. The code for the form is below:
class email
{
var $form;
var $message;
var $recipient = "test@test.co.uk";
var $from = "test@test.co.uk";
function email($recipient="test@test.co.uk",$from="test@test.co.uk")
{
$this->form = new form;
$this->form->details = array(array('name' => 'form_id','type' => 'hidden','value' => 'emailform'));
$this->recipient = $recipient;
$this->from = $from;
}
function initializeEmail($post)
{
if((isset($post['form_id']) && $post['form_id']=='emailform') && !$this->form->validation = $this->form->validateForm($post))
{
$unique_sep = md5(uniqid(time()));
$message = "";
foreach($_POST as $k => $v)
if($k != 'form_id' || $k != 'submit')
{
if(is_array($v))
$message .= $k . ": " . implode(",",$v) . "\n";
else
$message .= $k . ": " . $v . "\n";
}
$subject = "";
$headers .= "From: " . $this->from . "\n";
$headers .= "MIME-Version: 1.0\nContent-Type:" . " multipart/mixed;boundary=\"$unique_sep\";\n";
$headers .= "charset=\"iso-8859-1\"\nContent-Transfer-Encoding:" . "7bit\n\n";
$headers .= "If you are reading this, then your e-mail client does" . "not support MIME.\n";
$headers .= "--$unique_sep\n";
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$headers .= "Content-Transfer-Encoding: 7bit\n\n";
$headers .= $message."\n\n";
foreach($_FILES as $name => $file)
{
if(file_exists($file['tmp_name']))
{
$headers .= "--$unique_sep\n";
$headers .= "Content-Type: " . $file['type'] . "; " . "name=\"" . $file['name'] . "\"\n";
$headers .= "Content-Transfer-Encoding: " . "base64\n";
$headers .= "Content-Disposition: attachment\n\n";
$filedata = implode(file($file['tmp_name']), '');
$headers .= chunk_split(base64_encode($filedata));
}
}
$headers .= "--$unique_sep--\n";
mail($this->recipient, $subject, $message ,$headers);
$this->message = "Thankyou for your submission";
}
}
function outputEmail()
{
$emailstring = "";
$emailstring .= "<span class='red'>" . $this->message . "</span>";
$emailstring .= $this->form->createForm('multipart/form-data');
return $emailstring;
}
}
?>
Any chance anyone can help me out??
Cheers!