从表格中发送邮件的问题

发布于 2025-02-10 20:57:45 字数 7595 浏览 1 评论 0原文

我知道这里有类似的问题,但是我已经搜寻了很多,并认为我提出了解决方案,但它仍然不起作用。转到错误页面,没有发送邮件。请注意,我已经在提供的代码中隐藏了我的电子邮件,但是在$ webmaster_email中使用了hotmail.com地址。

我想包括表格,但太长了。但是,请注意,它包含许多脚本,这些脚本根据无线电和下拉的选择显示表单的各个部分。它的响应与我想要的完全一样。

它还包含表单脚本本身中某些输入的“必需”,因此不确定是否应将相同的支票包含在发送邮件PHP文件中。

这是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 protected]";

/*
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" );
}
?>

谢谢大家。

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 protected]";

/*
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文