提交表单后,我在旧网站上使用phpmailer发送电子邮件。
它正在正确发送输入文本,但未发送正确的选择选项。
这是我正在使用的 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="">
因此,无论我是否从下拉列表中选择说“小姐”,收到的电子邮件将始终以“先生”为标题。
这是提交时表单操作的邮件程序:
<?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('mail@mail.co.uk', 'Site');
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
?>
$_POST['title']
以上是我遇到问题的地方。如何更改代码以便从用户输入发送正确的选择选项?