【问题标题】:How come the sendmail.php file isn't working?为什么 sendmail.php 文件不起作用?
【发布时间】:2012-07-12 10:11:11
【问题描述】:
<?php

$error_msgs = array ();
$error = 0; 

if ($_POST['first_name']){
$first_name = $_POST['first_name'];
} else {
$error_msgs[] = "Please enter your first name";
$errors++; 
}

if ($_POST['last_name']){
$last_name = $_POST['last_name'];
} else {
$error_msgs[] = "Please enter your last name";
$errors++; 
}

if ($_POST['ssn']){
$ssn = $_POST['ssn'];
} else {
$error_msgs[] = "Please enter your 9 digit social security number";
$errors++; 
}

if ($_POST['phone']){
$phone = $_POST['phone'];
} else {
$error_msgs[] = "Please enter your phone number";
$errors++; 
}

if ($_POST['address']){
$address = $_POST['address'];
} else {
$error_msgs[] = "Please enter your address";
$errors++; 
}

if ($_POST['city']){
$city = $_POST['city'];
} else {
$error_msgs[] = "Please enter your city";
$errors++; 
}

if ($_POST['state']){
$state = $_POST['state'];
} else {
$error_msgs[] = "Please select your state";
$errors++; 
}

if ($_POST['zip']){
$zip = $_POST['zip'];
} else {
$error_msgs[] = "Please enter your 5 digit zip code";
$errors++; 
}

if ($_POST['position']){
$position = $_POST['position'];
} else {
$error_msgs[] = "Please enter position desired, or type N/A if open for discussion";
$errors++; 
}

if ($_POST['wage']){
$wage = $_POST['wage'];
} else {
$error_msgs[] = "Please enter 0.00 if open for discussion";
$errors++; 
}

if ($_POST['Emergencycontactname']){
$Emergencycontactname = $_POST['Emergencycontactname'];
} else {
$error_msgs[] = "Please enter your emergency contact's name";
$errors++; 
}

if ($_POST['Emergencycontactaddress']){
$Emergencycontactaddress = $_POST['Emergencycontactaddress'];
} else {
$error_msgs[] = "Please enter your emergency contact's address";
$errors++; 
}

if ($_POST['Emergencycontactcity']){
$Emergencycontactcity = $_POST['Emergencycontactcity'];
} else {
$error_msgs[] = "Please enter your emergency contact's city";
$errors++; 
}

if ($_POST['Emergencycontactstate']){
$Emergencycontactstate = $_POST['Emergencycontactstate'];
} else {
$error_msgs[] = "Please select your emergency contact's state";
$errors++; 
}

if ($_POST['Emergencycontactzip']){
$Emergencycontactzip = $_POST['Emergencycontactzip'];
} else {
$error_msgs[] = "Please enter your emergency contact's 5 digit zip code";
$errors++; 
}

if ($_POST['Emergencycontactphone']){
$Emergencycontactphone = $_POST['Emergencycontactphone'];
} else {
$error_msgs[] = "Please enter your emergency contact's phone number";
$errors++; 
}

if ($_POST['highest']){
$highest = $_POST['highest'];
} else {
$error_msgs[] = "Please enter your highest level of education";
$errors++; 
}

if ($_POST['degree']){
$degree = $_POST['degree'];
} else {
$error_msgs[] = "Please enter N/A if none";
$errors++; 
}

if ($_POST['age']){
$age = $_POST['age'];
} else {
$error_msgs[] = "Please enter yes or no";
$errors++; 
}

if ($_POST['problems']){
$problems = $_POST['problems'];
} else {
$error_msgs[] = "Please enter yes or no";
$errors++; 
}

if ($_POST['shiftwork']){
$shiftwork = $_POST['shiftwork'];
} else {
$error_msgs[] = "Please enter yes or no";
$errors++; 
}

if ($_POST['apprenticeship']){
$apprenticeship = $_POST['apprenticeship'];
} else {
$error_msgs[] = "Please enter yes or no";
$errors++; 
}

if ($_POST['disabilities']){
$disabilities = $_POST['disabilities'];
} else {
$error_msgs[] = "Please enter yes or no";
$errors++; 
}

if ($_POST['ifyes']){
$ifyes = $_POST['ifyes'];
} else {
$error_msgs[] = "If you answered no to above question, type N/A";
$errors++; 
}

if ($_POST['accommodate']){
$accommodate = $_POST['accommodate'];
} else {
$error_msgs[] = "Type N/A if you answered N/A for above question";
$errors++; 
}

if ($_POST['experience']){
$experience = $_POST['experience'];
} else {
$error_msgs[] = "Please enter yes or no";
$errors++; 
}

if ($_POST['ifyes2']){
$ifyes2 = $_POST['ifyes2'];
} else {
$error_msgs[] = "If you answered no to above, type N/A, otherwise describe";
$errors++; 
}

if ($_POST['cname']){
$cname = $_POST['cname'];
} else {
$error_msgs[] = "Please enter company name";
$errors++; 
}

if ($_POST['caddress']){
$caddress = $_POST['caddress'];
} else {
$error_msgs[] = "Please enter company address";
$errors++; 
}

if ($_POST['cphone']){
$cphone = $_POST['cphone'];
} else {
$error_msgs[] = "Please enter company phone number";
$errors++; 
}

if ($_POST['ccperson']){
$ccperson = $_POST['ccperson'];
} else {
$error_msgs[] = "Please enter company contact person's name";
$errors++; 
}

if ($_POST['ctype']){
$ctype = $_POST['ctype'];
} else {
$error_msgs[] = "Please enter type of work";
$errors++; 
}

if ($_POST['cwage']){
$cwage = $_POST['cwage'];
} else {
$error_msgs[] = "Please enter wage earned";
$errors++; 
}

if ($_POST['cstart']){
$cstart = $POST['cstart'];
} else {
$error_msgs[] = "Please enter date started";
$errors++; 
}

if ($_POST['cend']){
$cend = $POST['cend'];
} else {
$error_msgs[] = "Please enter date ended";
$errors++; 
}

if ($_POST['reason']){
$reason = $_POST['reason'];
} else {
$error_msgs[] = "Please enter reason for leaving";
$errors++; 
}

if ($_POST['cname2']){
$cname2 = $_POST['cname2'];
} else {
$error_msgs[] = "Please enter company name or type N/A";
$errors++; 
}

if ($_POST['caddress2']){
$caddress2 = $_POST['caddress2'];
} else {
$error_msgs[] = "Please enter company address or type N/A";
$errors++; 
}

if ($_POST['cphone2']){
$cphone2 = $_POST['cphone2'];
} else {
 $error_msgs[] = "Please enter company phone number or type N/A";
$errors++; 
}

if ($_POST['ccperson2']){
$ccperson2 = $_POST['ccperson2'];
} else {
$error_msgs[] = "Please enter company contact person's name or type N/A";
$errors++; 
}

if ($_POST['ctype2']){
$ctype2 = $_POST['ctype2'];
} else {
$error_msgs[] = "Please enter type of work or type N/A";
$errors++; 
}

if ($_POST['cwage2']){
$cwage2 = $_POST['cwage2'];
} else {
$error_msgs[] = "Please enter wage earned or type 0.00 if N/A";
$errors++; 
}

if ($_POST['cstart2']){
$cstart2 = $POST['cstart2'];
} else {
$error_msgs[] = "Please enter date started or type N/A";
$errors++; 
}

if ($_POST['cend2']){
$cend2 = $POST['cend2'];
} else {
$error_msgs[] = "Please enter date ended or type N/A";
$errors++; 
}

if ($_POST['reason2']){
$reason2 = $_POST['reason2'];
} else {
$error_msgs[] = "Please enter reason for leaving or type N/A";
$errors++; 
}

if ($_POST['cname3']){
$cname3 = $_POST['cname3'];
} else {
$error_msgs[] = "Please enter company name or type N/A";
$errors++; 
}

if ($_POST['caddress3']){
$caddress3 = $_POST['caddress3'];
} else {
$error_msgs[] = "Please enter company address or type N/A";
$errors++; 
}

if ($_POST['cphone3']){
$cphone3 = $_POST['cphone3'];
} else {
$error_msgs[] = "Please enter company phone number or type N/A";
$errors++; 
}

if ($_POST['ccperson3']){
$ccperson3 = $_POST['ccperson3'];
} else {
$error_msgs[] = "Please enter company contact person's name or type N/A";
$errors++; 
}

if ($_POST['ctype3']){
$ctype3 = $_POST['ctype3'];
} else {
$error_msgs[] = "Please enter type of work or type N/A";
$errors++; 
}

if ($_POST['cwage3']){
$cwage3 = $_POST['cwage3'];
} else {
$error_msgs[] = "Please enter wage earned or type 0.00 if N/A";
$errors++; 
}

if ($_POST['cstart3']){
$cstart3 = $POST['cstart3'];
} else {
$error_msgs[] = "Please enter date started or type N/A";
$errors++; 
}

if ($_POST['cend3']){
$cend3 = $POST['cend3'];
} else {
$error_msgs[] = "Please enter date ended or type N/A";
$errors++; 
}

if ($_POST['reason3']){
$reason3 = $_POST['reason3'];
} else {
$error_msgs[] = "Please enter reason for leaving or type N/A";
$errors++; 
}

if ($_POST['maywe']){
$maywe = $_POST['maywe'];
} else {
$error_msgs[] = "Type names of companies you do not want us to contact, or type, ok all";
$errors++; 
}

if ($_POST['additional']){
$additional = $_POST['additional'];
} else {
$error_msgs[] = "Type N/A if you do not have any additional information";
$errors++; 
}

if ($_POST['fn']){
$fn = $_POST['fn'];
} else {
$error_msgs[] = "Please enter your full name";
$errors++; 
}

if ($_POST['electronicsignssn']){
$electronicsignssn = $_POST['electronicsignssn'];
} else {
$error_msgs[] = "Please enter your 9 digit social security number";
$errors++; 
}

if ($_POST['emailaddress']){
$emailaddress = $_POST['emailaddress'];
} else {
$error_msgs[] = "Please enter your email address";
$errors++; 
}

if ($errors > 0) {
foreach ($error_msgs as &$msg) {
"There is/are " . $errors . " error(s) in your submission, please click your browser's back button and correct them.<br/>";
echo $msg . "<br/>";
}
} else {
mail( "heitfieldmichael@yahoo.com, "Application for $fn", $body, "From: $emailaddress\r\n" );
header( "Location: http://www.creativeurethanes.com/Thankyoupageforjobapplication.html" );
}
?>

变化很大

<?php
$first_name = $_REQUEST['first_name'] ;
$last_name = $_REQUEST['last_name'] ;
$ssn = $_REQUEST['ssn'] ;
$phone = $_REQUEST['phone'] ;
$address = $_REQUEST['address'] ;
$city = $_REQUEST['city'] ;
$state = $_REQUEST['state'] ;
$zip = $_REQUEST['zip'] ;
$position = $_REQUEST['position'] ;
$wage = $_REQUEST['wage'] ;
$911name = $_REQUEST['911name'] ;
$911address = $_REQUEST['911address'] ;
$911city = $_REQUEST['911city'] ;
$911state = $_REQUEST['911state'] ;
$911zip = $_REQUEST['911zip'] ;
$911phone = $_REQUEST['911phone'] ;
$highest = $_REQUEST['highest'] ;
$degrees = $_REQUEST['degrees'] ;
$age = $_REQUEST['age'] ;
$problems = $_REQUEST['problems'] ;
$shiftwork = $_REQUEST['shiftwork'] ;
$apprenticeship = $_REQUEST['apprenticeship'] ;
$disabilities = $_REQUEST['disabilities'] ;
$ifyes = $_REQUEST['ifyes'] ;
$accomodate = $_REQUEST['accomodate'] ;
$experience = $_REQUEST['experience'] ;
$ifyes2 = $_REQUEST['ifyes2'] ;
$cname = $_REQUEST['cname'] ;
$caddress = $_REQUEST['caddress'] ;
$cphone = $_REQUEST['cphone'] ;
$ccperson = $_REQUEST['ccperson'] ;
$ctype = $_REQUEST['ctype'] ;
$cwage = $_REQUEST['cwage'] ;
$sted = $_REQUEST['sted'] ;
$reason = $_REQUEST['reason'] ;
$cname2 = $_REQUEST['cname2'] ;
$caddress2 = $_REQUEST['caddress2'] ;
$cphone2 = $_REQUEST['cphone2'] ;
$ccperson2 = $_REQUEST['ccperson2'] ;
$ctype2 = $_REQUEST['ctype2'] ;
$cwage2 = $_REQUEST['cwage2'] ;
$sted2 = $_REQUEST['sted2'] ;
$reason2 = $_REQUEST['reason2'] ;
$cname3 = $_REQUEST['cname3'] ;
$caddress3 = $_REQUEST['caddress3'] ;
$cphone3 = $_REQUEST['cphone3'] ;
$ccperson3 = $_REQUEST['ccperson3'] ;
$ctype3 = $_REQUEST['ctype3'] ;
$cwage3 = $_REQUEST['cwage3'] ;
$sted3 = $_REQUEST['sted3'] ;
$reason3 = $_REQUEST['reason3'] ;
$maywe = $_REQUEST['maywe'] ;
$additional = $_REQUEST['additional'] ;
$electronicsignfn = $_REQUEST['electronicsignfn'] ;
$electronicsignssn = $_REQUEST['electronicsignssn'] ;
$emailaddress = $_REQUEST['emailaddress'] ;

mail( "cuinfo@creativeurethanes.com", "Application",
$first_name, $last_name, $ssn, $phone, $address, $city, $state, $zip, $position, $wage, $911name, $911address, $911city, $911state, $911zip, $911phone, $highest, $degrees, $age, $problems, $shiftwork, $apprenticeship, $disabilities, $ifyes, $accomodate, $experience, $ifyes2, $cname, $caddress, $cphone, $ccperson, $ctype, $cwage, $sted, $reason, $cname2, $caddress2, $cphone2, $ccperson2, $ctype2, $cwage2, $sted2, $reason2, $cname3, $caddress3, $cphone3, $ccperson3, $ctype3, $cwage3, $sted3, $reason3, $maywe, $additional, $electronicsignfn, $electronicsignssn, $emailaddress, "From: $emailaddress" );
header( "Location: http://www.creativeurethanes.com/Thankyou.html" );
?>

所以,我想到了 php,但不断出现内部服务器错误。我做错了什么?我已经设置好 sendmail.php 文件、Thankyou.html 文件和应用程序文件。为什么当我点击提交进行测试运行时,它会转到 HTTP 500 内部服务器错误页面?

【问题讨论】:

  • 您查看过mail() 的文档以了解它所期望的参数吗?
  • @andrewsi 我不知道。我不是一个PHP的人。这是我的另一个问题的延续。 “提交按钮操作”
  • 发送表格到我公司的主邮箱。但我无法让它工作。
  • 你可以试试,去creativeurethanes.com点击加入我们标签,填写信息。不要打扰真实的信息,它不会起作用。然后点击提交,这就是我所知道的。啊啊啊
  • 答案就在文档中。

标签: php forms email send


【解决方案1】:

我同意其他人的观点,您真的应该阅读 cmets 中链接的邮件功能。函数的结构是mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

您需要将邮件正文中所需的所有内容放入一个字符串中,然后将该字符串传递给邮件函数。最后,它看起来像

mail( "cuinfo@creativeurethanes.com", "Application", $body, "From: $emailaddress" );

确保您正确格式化 $body,使其不是一大堆文本(在每一行之后放置 \r\n)

代码示例如下:

<?php
$body = "First Name: ".$_REQUEST['first_name'] ."\r\n";
$body .= "Last Name: ".$_REQUEST['last_name'] ."\r\n";
$body .= "SSN Name: ".$_REQUEST['ssn'] ."\r\n";

// Keep adding the information here

mail( "cuinfo@creativeurethanes.com", "Application",$body, "From: $emailaddress\r\n" );
header( "Location: http://www.creativeurethanes.com/Thankyou.html" );

?>

确保您还在发件人地址后添加 \r\n

【讨论】:

  • 哦,好吧,我的意思是所有信息都来自一个表格。所以我不必去,$first_name、$last_name、$ssn。等每个值?这些表格令人困惑。
  • 我无法发布表单,因为它有 5,000 个字符太长
  • 不,您不必这样做。您可以通过 $body = $_REQUEST['first_name'] 创建正文。 "\r\n"; $body.= $_REQUEST['last_name'] 。 "\r\n"; $body.= $_REQUEST['ssn'] 。 "\r\n";等等等等。您还可以通过向主体添加更多内容来使其更好,例如 $body = "First Name:"。 $_REQUEST['first_name'] 。 "\r\n"; $body.= "姓氏:".$_REQUEST['last_name'] 。 "\r\n"; $body.="SSN:"。 $_REQUEST['ssn'] 。 "\r\n";
  • 我会在邮件之后更改代码(等)或之后
  • 你会在调用 mail 函数之前创建 $body,但仍然在 标签内,因为它仍然是 php。
【解决方案2】:

1: php 中有一些命名变量的约定。看看http://de3.php.net/manual/en/language.variables.basics.php -> 他们不能以数字开头。
2:$_REQUEST 是超全局的,但您不能假设所有值都已设置。您必须使用 isset()-funcion (http://de3.php.net/manual/en/function.isset.php) 检查每个。
3:如您所见,您不能指望邮件功能始终有效。如果您未使用 (if(mail(...))) 进行检查,请勿将用户重定向到成功站点。
4:要找出它抛出 500 错误的原因,您必须检查您的服务器日志。如果您的服务器配置为不显示它们,则由于 php 错误可能会出现此错误。您可能必须在脚本中首先重新配置和/或设置这些行:

ini_set('display_errors', 1);
error_reporting(E_ALL);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-24
    • 2013-10-22
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-17
    • 2021-06-24
    相关资源
    最近更新 更多