0

I know that there are similar questions on here, but I have scoured many and thought that I had come up with the solution but it still isn't working. Going to error page and no mail sent. Please note I have hidden my email in the code supplied but was using a hotmail.com address in the $webmaster_email.

I wanted to include the form but it is too long. Please note however that it includes a lot of script which shows/hides sections of the form depending on radio and drop-down choices. It is responding exactly like I wanted it to.

It also contains 'required' for certain inputs within the form script itself so not sure if the same check should be included in the send mail php file.

Here is the script for landformsend_mail.php:

<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "email@hotmail.com";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "landformtest.php";
$error_page = "landform_not_sent.html";
$thankyou_page = "landform_thank_you.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$Name = $_REQUEST['Name'] ;
$ifowner = $_REQUEST['ifowner'] ;
$actualowner = $_REQUEST['actualowner'] ;
$Email = $_REQUEST['Email'] ;
$Phone = $_REQUEST['Phone'] ;
$timezone = $_REQUEST['timezone'] ;
$callafter = $_REQUEST['callafter'] ;
$callbefore = $_REQUEST['callbefore'] ;
$street = $_REQUEST['street'] ;
$city = $_REQUEST['city'] ;
$county = $_REQUEST['county'] ;
$state = $_REQUEST['state'] ;
$zipcode = $_REQUEST['zipcode'] ;
$apn = $_REQUEST['apn'] ;
$parcelsize = $_REQUEST['$parcelsize'] ;
$landunits = $_REQUEST['$landunits'] ;
$access = $_REQUEST['access'] ;
$roadowner = $_REQUEST['roadowner'] ;
$roadtype = $_REQUEST['roadtype'] ;
$othersurfacedetails = $_REQUEST['othersurfacedetails'] ;
$easedescr = $_REQUEST['easedescr'] ;
$tempaccess = $_REQUEST['tempaccess'] ;
$tempaccessdetails = $_REQUEST['tempaccessdetails'] ;
$ifsurvey = $_REQUEST['ifsurvey'] ;
$datesurvey = $_REQUEST['datesurvey'] ;
$ifperc = $_REQUEST['ifperc'] ;
$dateperc = $_REQUEST['dateperc'] ;
$septicpermit = $_REQUEST['septicpermit'] ;
$ifflood = $_REQUEST['ifflood'] ;
$ifelectric = $_REQUEST['ifelectric'] ;
$offgridelectric = $_REQUEST['offgridelectric'] ;
$altelecticdetails = $_REQUEST['altelectricdetails'] ;
$ifwater = $_REQUEST['ifwater'] ;
$datewell = $_REQUEST['datewell'] ;
$potablewellwater = $_REQUEST['potablewellwater'] ;
$ifsewer = $_REQUEST['ifsewer'] ;
$dateseptic = $_REQUEST['dateseptic'] ;
$currentzoning = $_REQUEST['currentzoning'] ;
$futurezoning = $_REQUEST['futurezoning'] ;
$futurezoningdetails = $_REQUEST['futurezoningdetails'] ;
$restrictions = $_REQUEST['restrictions'] ;
$restrictiondetails = $_REQUEST['restrictiondetails'] ;
$farming = $_REQUEST['farming'] ;
$somefarmingdetails = $_REQUEST['somefarmingdetails'] ;
$landuse = $_REQUEST['landuse'] ;
$description = $_REQUEST['description'] ;
$msg = 
"Name: " . $Name . "\r\n" . 
"If owner: " . $ifowner . "\r\n" . 
"Actual owner: " . $actualowner . "\r\n" . 
"Email: " . $Email . "\r\n" . 
"Phone: " . $Phone . "\r\n" .
"Time zone: " . $timezone . "\r\n" . 
"Call after: " . $callafter . "\r\n" . 
"But before: " . $callbefore . "\r\n" . 
"Property street address: " . $street . "\r\n" . 
"Property city: " . $city . "\r\n" . 
"Propety county: " . $county . "\r\n" . 
"Property state: " . $state . "\r\n" . 
"Property zipcode: " . $zipcode . "\r\n" . 
"APN: " . $apn . "\r\n" . 
"Parcel size: " . $parcelsize . "\r\n" . 
"Land units: " . $landunits . "\r\n" . 
"Access to land: " . $access . "\r\n" . 
"Road owner: " . $roadowner . "\r\n" . 
"Road surface type: " . $roadtype . "\r\n" . 
"Other surface type: " . $othersurfacedetails . "\r\n" . 
"Details of easement: " . $easedescr . "\r\n" . 
"Is temporary access available?: " . $tempaccess . "\r\n" . 
"Temporary access details: " . $tempaccessdetails . "\r\n" . 
"Has a survey been done? : " . $ifsurvey . "\r\n" . 
"Date of survey: " . $datesurvey . "\r\n" . 
"Has a perc test been done? : " . $ifperc . "\r\n" . 
"Date of perc test: " . $dateperc . "\r\n" . 
"Is there a septic permit? : " . $septicpermit . "\r\n" . 
"Is the land within a flood zone? : " . $ifflood . "\r\n" . 
"Is there electric? : " . $ifelectric . "\r\n" . 
"Is there an alternate source of electricity? : " . $offgridelectric . "\r\n" . 
"Details of the alt electric source: " . $altelecticdetails . "\r\n" . 
"Is there water? : " . $ifwater . "\r\n" . 
"Date well drilled: " . $datewell . "\r\n" . 
"Is the water drinkable? : " . $potablewellwater . "\r\n" . 
"Is there a sewer system? : " . $ifsewer . "\r\n" . 
"Date septic system was installed: " . $dateseptic . "\r\n" . 
"Current land zoning: " . $currentzoning . "\r\n" . 
"Are there plans to change the zoning?: " . $futurezoning . "\r\n" .
"Details of future zoning: " . $futurezoningdetails . "\r\n" .
"Are there any Use restrictions? : " . $restrictions . "\r\n" .
"Details of any restrictions: " . $restrictiondetails . "\r\n" .
"Is farming permitted? : " . $farming . "\r\n" .
"Details of any farming restrictions: " . $somefarmingdetails . "\r\n" .
"What is the land being used for at this time? : " . $landuse . "\r\n" .
"Description of land: " . $description ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str)) {
        return true;
    }
    else {
        return false;
    }
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['Email'])) {
header( "Location: $error_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($Name) || empty($Email) || empty($city) || empty($county) || empty($state)) {
header( "Location: $error_page" );
}

/* 
If email injection is detected, redirect to the error page.
If you add a form field, you should add it here.
*/
elseif ( isInjected($Email) || isInjected($Name) || isInjected($ifowner) || isInjected($actualowner) || isInjected($Phone) || isInjected($timezone) || isInjected($callafter) || isInjected($callbefore) || isInjected($street) || isInjected($city) || isInjected($county) || isInjected($state) || isInjected($zipcode) || isInjected($apn) || isInjected($parcelsize) || isInjected($landunits) || isInjected($access) || isInjected($roadowner) || isInjected($roadtype) || isInjected($othersurfacedetails) || isInjected($easedescr) || isInjected($tempaccess) || isInjected($tempaccessdetails) || isInjected($ifsurvey) || isInjected($datesurvey) || isInjected($ifperc) || isInjected($dateperc) || isInjected($septicpermit) || isInjected($ifflood) || isInjected($ifelectric) || isInjected($offgridelectric) || isInjected($altelecticdetails) || isInjected($ifwater) || isInjected($datewell) || isInjected($potablewellwater) || isInjected($ifsewer) || isInjected($dateseptic) || isInjected($currentzoning) || isInjected($futurezoning) || isInjected($futurezoningdetails) || isInjected($restrictions) || isInjected($restrictiondetails) || isInjected($farming) || isInjected($somefarmingdetails) || isInjected($landuse) || isInjected($description) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {

    mail( "$webmaster_email", "Landform Results", $msg );

    header( "Location: $thankyou_page" );
}
?>

Thank you all.

user3783243
  • 5,368
  • 5
  • 22
  • 41
  • I was editing it as I was hoping to add the additional script in a comment but couldn't. No room for the landformtest.php form script though. – Dragonwalker Jun 24 '22 at 19:19
  • This code snippet is already too long. Please define `it still isn't working`, do you get an error, 500 status code, blank page, sent to `landform_not_sent.html`, something else? – user3783243 Jun 24 '22 at 19:20
  • It is taking me to the error page and no mail received. Sorry when I originally typed the question I had been more specific. – Dragonwalker Jun 24 '22 at 19:23
  • i.e. landform_not_sent.html – Dragonwalker Jun 24 '22 at 19:25
  • Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – ADyson Jun 24 '22 at 19:26
  • Put diagnostic messaging in your three blocks that send `header( "Location: $error_page" );` and see which one is occuring. – user3783243 Jun 24 '22 at 19:27
  • @ADyson `mail(` isn't being called so don't think that's relevant for this one. – user3783243 Jun 24 '22 at 19:28
  • I can also try my mail( form which also wasn't working and add diagnostics to it, but I have read that the above code is better than using mailto. Is this correct? I may be away from the computer for a while but will check back later. Thank you all. – Dragonwalker Jun 24 '22 at 19:58
  • `mailto` sends from the user's system, not your server. – user3783243 Jun 24 '22 at 20:00
  • Nothing I am trying is working. I even retried my mail() php file and it gives me the text telling the user to try again because it didn't submit. I may have to start from scratch. Is there anything I have to do at the server's end? Don't remember having to do that for the other forms that work. Could it have something about the form using lots of scripts? Each question has a name so should work I presume even if some sections don't show depending upon the responses. – Dragonwalker Jun 25 '22 at 20:22
  • Please let me know if anyone can help.I am still struggling and asked elsewhere but the response there was using a completely different method and far more advanced than I can understand. – Dragonwalker Jun 29 '22 at 17:53

0 Answers0