我使用这个PHP代码根据输入到html表单的用户信息发送电子邮件。发送的电子邮件没有错误,但格式不符合预期。
<?php
$errors = '';
$_TechnicianName = $_POST['TechnicianName'];
$_TechnicianeMail = $_POST['TechnicianeMail'];
$_JobNumber = $_POST['JobNumber'];
$_CompanyName = $_POST['CompanyName'];
$_MachineNumber = $_POST['MachineNumber'];
$_StartTime = $_POST['StartTime'];
$_FinishTime = $_POST['FinishTime'];
$_TravelTime = $_POST['TravelTime'];
$_SiteContact = $_POST['SiteContact'];
$_CallOffNotes = $_POST['CallOffNotes'];
$_RTF = $_POST['RTF'];
$_MachineDown = $_POST['MachineDown'];
$_Chargeable = $_POST['Chargeable'];
$_eMailAddress = $_POST['eMailAddress'];
$_PartNo01 = $_POST['PartNo01'];
$_Description01 = $_POST['Description01'];
$_Qty01 = $_POST['Qty01'];
$_PartNo02 = $_POST['PartNo02'];
$_Description02 = $_POST['Description02'];
$_Qty02 = $_POST['Qty02'];
$_PartNo03 = $_POST['PartNo03'];
$_Description03 = $_POST['Description03'];
$_Qty03 = $_POST['Qty03'];
$_PartNo04 = $_POST['PartNo04'];
$_Description04 = $_POST['Description04'];
$_Qty04 = $_POST['Qty04'];
$_PartNo05 = $_POST['PartNo05'];
$_Description05 = $_POST['Description05'];
$_Qty05 = $_POST['Qty05'];
$_PartNo06 = $_POST['PartNo06'];
$_Description06 = $_POST['Description06'];
$_Qty06 = $_POST['Qty06'];
$_PartNo07 = $_POST['PartNo07'];
$_Description07 = $_POST['Description07'];
$_Qty07 = $_POST['Qty07'];
$_PartNo08 = $_POST['PartNo08'];
$_Description08 = $_POST['Description08'];
$_Qty08 = $_POST['Qty08'];
$_PartNo09 = $_POST['PartNo09'];
$_Description09 = $_POST['Description09'];
$_Qty09 = $_POST['Qty09'];
$_PartNo10 = $_POST['PartNo10'];
$_Description10 = $_POST['Description10'];
$_Qty10 = $_POST['Qty10'];
$_PartNo11 = $_POST['PartNo11'];
$_Description11 = $_POST['Description11'];
$_Qty11 = $_POST['Qty11'];
$_PartNo12 = $_POST['PartNo12'];
$_Description12 = $_POST['Description12'];
$_Qty12 = $_POST['Qty12'];
$_Meter1 = $_POST['Meter1'];
$_Meter2 = $_POST['Meter2'];
$_Meter3 = $_POST['Meter3'];
$_Meter4 = $_POST['Meter4'];
$_Meter5 = $_POST['Meter5'];
if (!empty($_PartNo01)) {$PartsNumberString = "Part 1: $_Qty01 x $_PartNo01 $_Description01 \n";}
if (!empty($_PartNo02)) {$PartsNumberString .= "Part 2: $_Qty02 x $_PartNo02 $_Description02 \n";}
if (!empty($_PartNo03)) {$PartsNumberString .= "Part 3: $_Qty03 x $_PartNo03 $_Description03 \n";}
if (!empty($_PartNo04)) {$PartsNumberString .= "Part 4: $_Qty04 x $_PartNo04 $_Description04 \n";}
if (!empty($_PartNo05)) {$PartsNumberString .= "Part 5: $_Qty05 x $_PartNo05 $_Description05 \n";}
if (!empty($_PartNo06)) {$PartsNumberString .= "Part 6: $_Qty06 x $_PartNo06 $_Description06 \n";}
if (!empty($_PartNo07)) {$PartsNumberString .= "Part 7: $_Qty07 x $_PartNo07 $_Description07 \n";}
if (!empty($_PartNo08)) {$PartsNumberString .= "Part 8: $_Qty08 x $_PartNo08 $_Description08 \n";}
if (!empty($_PartNo09)) {$PartsNumberString .= "Part 9: $_Qty09 x $_PartNo09 $_Description09 \n";}
if (!empty($_PartNo10)) {$PartsNumberString .= "Part 10: $_Qty10 x $_PartNo10 $_Description10 \n";}
if (!empty($_PartNo11)) {$PartsNumberString .= "Part 11: $_Qty11 x $_PartNo11 $_Description11 \n";}
if (!empty($_PartNo12)) {$PartsNumberString .= "Part 12: $_Qty12 x $_PartNo12 $_Description12";}
if( empty($errors))
{
$to = "supplies@boileau.com.au";
$email_subject = "Job Close: $_TechnicianName";
$email_body = "Job Closed:\nJob Number: $_JobNumber";
$email_body .= "\r\nCompany Name: $_CompanyName";
$email_body .= "\r\nMachine Number: $_MachineNumber";
$email_body .= "\r\nStart Time: $_StartTime";
$email_body .= "\r\nCompletion Time: $_FinishTime";
$email_body .= "\r\nTravel Time: $_TravelTime";
$email_body .= "\r\nWork Time: TBA";
$email_body .= "\r\nSite Contact: $_SiteContact";
$email_body .= "\r\nCall Off Notes: $_CallOffNotes";
$email_body .= "\r\nRTF Required: $_RTF";
$email_body .= "\r\nMachine Down: $_MachineDown";
$email_body .= "\r\nChargeable: $_Chargeable";
$email_body .= "\r\nEmail Address: $_eMailAddress";
$email_body .= "\r\n$PartsNumberString";
$email_body .= "\r\nMeter 1: $_Meter1";
$email_body .= "\r\nMeter 2: $_Meter2";
$email_body .= "\r\nMeter 3: $_Meter3";
$email_body .= "\r\nMeter 4: $_Meter4";
$email_body .= "\r\nMeter 5: $_Meter5";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: $_TechnicianeMail";
$headers[] = "CC: $_TechnicianeMail";
$headers[] = "CC: bbrewer@boileau.com.au";
$headers[] = "Reply-To: $_TechnicianeMail";
mail($to,$email_subject,$email_body, implode("\r\n", $headers));
//redirect to the 'thank you' page
header('Location: '.$_TechnicianName.'/CloseJob.html');
}
?>
收到的电子邮件看起来像这样......
Job Closed:
Job Number: 83553
Company Name: Some Company
Machine Number: 14663
Start Time: 16:30
Completion Time: 17:00
Travel Time: 1 Minutes
Work Time: TBA
Site Contact: Gail
Call Off Notes: Cleaned DADF rollers. All test ok RTF Required: no Machine Down: no
Chargeable: no
Email Address:
Part 1: 2 x 022k74870 roller
Meter 1: 352285
Meter 2: 0
Meter 3: 0
Meter 4: 0
Meter 5:
Line开头 Call Off注意:应为3行,但\ r \ n命令在此处不起作用。我使用像这样的nl2br测试了mail命令......
mail($to,$email_subject,nl2br($email_body), implode("\r\n", $headers));
并收到了这个......
Site Contact: Gail<br />
Call Off Notes: Cleaned DADF rollers. All test ok<br /> RTF Required: no<br /> Machine Down: no<br />
Chargeable: no<br />