PHP form not working after update

Again there is a mail form script that does not work again after updating php.
What should be changed, please?


<script>

$(document).keypress(

function(event){

if (event.which == '13') {

event.preventDefault();

}

});



$(".custom-upload").each(function() {

var uploadForm = $(this);

var uploadInput = $(this).find('#chooseFile');

$(uploadInput).bind('change', function () {

var filename = $(uploadInput).val();

if (/^\s*$/.test(filename)) {

$(uploadForm).find(".file-upload").removeClass('active');

$(uploadForm).find("#noFile").text("No file chosen...");

}

else {

$(uploadForm).find(".file-upload").addClass('active');

$(uploadForm).find("#noFile").text(filename.replace("C:\\fakepath\\", ""));

}

});

});
</script>
<?php

$ip = $_SERVER['REMOTE_ADDR']; // get ip to short variable name for logging purposes 

$to = "my@website.com";
$subject= "inschrijving op de website";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$website = $_POST['website'];
$beschrijving = $_POST['beschrijving'];
$socialURL = $_POST['socialURL'];
$cmname = $_POST['cmname'];
$faciliteit = $_POST['faciliteit'];
$add = $_POST['add'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$keywords1 = $_POST['keywords1'];
$keywords2 = $_POST['keywords2'];
$keywords3 = $_POST['keywords3'];
$keywords4 = $_POST['keywords4'];
$keywords5 = $_POST['keywords5'];
$keywords6 = $_POST['keywords6'];
$prijslijst = $_POST['prijslijst'];
$openingsuren = $_POST['openingsuren'];
$klikbaar = $_POST['klikbaar'];
$socialFB = $_POST['socialFB'];
$socialTW = $_POST['socialTW'];
$socialIN = $_POST['socialIN'];
$socialGP = $_POST['socialGP'];
$opmerking = $_POST['opmerking'];
$message = "
Faciliteit: $faciliteit
Naam bedrijf: $cmname
Adres: $add, $zip $city

Beschrijving:
$beschrijving

Video:
$socialURL

Kernwoorden: 
$keywords1
$keywords2
$keywords3
$keywords4
$keywords5
$keywords6

Prijslijst:
$prijslijst

Openklikbare tekst:
$klikbaar

Contactpersoon: $name
Telefoon: $phone
Email: $email
Website: $website

Openingsuren: 
$openingsuren

Facebook: $socialFB
Instagram: $socialIN
Twitter: $socialTW
Google Plus: $socialGP

Verdere opmerkingen:
$opmerking
";
  $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
         $headers = "From: $email\r\n" .
         "MIME-Version: 1.0\r\n" .
            "Content-Type: multipart/mixed;\r\n" .
            " boundary=\"{$mime_boundary}\"";
         $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";
         foreach($_FILES as $userfile)
         {
            $tmp_name = $userfile['tmp_name'];
            $type = $userfile['type'];
            $name = $userfile['name'];
            $size = $userfile['size'];
            if (file_exists($tmp_name))
            {
               if(is_uploaded_file($tmp_name))
               {
                  $file = fopen($tmp_name,'rb');
                  $data = fread($file,filesize($tmp_name));
                  fclose($file);
                  $data = chunk_split(base64_encode($data));
               }
               $message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$type};\n" .
                  " name=\"{$name}\"\n" .
                  "Content-Disposition: attachment;\n" .
                  " filename=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
               $data . "\n\n";
            }
         }
         $message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
   echo "Dankje om mee te helpen aan de opbouw van deze site.<br>Ik neem je gegevens door en contacteer je zo snel mogelijk.";
else
   echo "Error in mail.<br>Probeer opnieuw door hieronder te klikken.";
?>

How can this form be adjusted to latest php version, please?
Thanks.

Define “does not work”.

2 Likes

For clarity, is this the same form that doesn’t work in your other thread? Should the two threads be merged together? Do they fail in the same way, or in different ways?

1 Like

Welcome to Sitepoint.

All the above and also, which version of PHP where you on and which are you on now?

SOLVED in the other thread:
Seems this was the solution:
replace $headers = “From: $email\r\n”
into $headers = “From: myaddress@mydomain.com\r\n” .

Thanks for your fast reaction!

2 Likes