我在舊網站上使用phpmailer在表單提交後發送電子郵件。如何解析HTML選擇選項值到PHP郵件程序
它正確地發送輸入文本,但沒有發送正確的選擇選項。
這裏是PHP/HTML頁面,我使用:
// array to create title select options
<?php
$selectArray1 = array ('Mr'=>'Mr',
'Mrs'=>'Mrs',
'Miss'=>'Miss',
'Ms'=>'Ms',
'Dr'=>'Dr');
?>
// below select box only sending the first option (Mr)
<label for="title">Title</label>
<select id="title" name="title[]">
<?php
foreach ($selectArray1 as $val_title){
echo "<option value=\"$val_title\">";
echo $val_title;
echo "</option>";
}
?>
</select>
//below input in sending correctly
<label for="name">Name</label></td>
<input id="name" name="name" maxlength="50" type="text" value="">
所以,如果我選擇說,從下拉菜單中「小姐」,當收到總會有「先生」爲標題的電子郵件不管。
下面是是表單動作submited當郵寄者:
<?php
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/Site/config.php');
// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/Site/lib/MailClass.inc');
// instantiate the class
$mailer = new FreakMailer();
// Set the subject
$mailer->Subject = 'Finance Enquiry - Site.co.uk';
// Body
$mailer->Body = 'Finance Enquiry from Site.co.uk' . "\n\n" . $_POST['title'] . "\n\n" . $_POST['name'] . "\n\n" . $_POST['user-email'];
// Add an address to send to.
$mailer->AddAddress('[email protected]', 'Site');
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
?>
上述$_POST['title']
是我在哪裏有問題。我如何更改代碼以便從用戶輸入中發送正確的選擇選項?
我刪除了[],它仍然沒有工作,但後來改變了標題的所有實例,以標題形式(除了標題其他一切事情),它似乎是現在的工作 – AfromanJ
這聽起來有點不可思議,因爲我的代碼對我很運行廉價的網絡託管商。因此它可能取決於您的PHP配置。 []的名字肯定是錯誤的,但我很高興你找到了解決問題的方法。 –