I am using phpmailer on an old website to send an email once a form has been submit.
It is sending input text correctly but is not sending the correct select option.
Here is the PHP/HTML page i am using:
// 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="">
So no matter if i select say "Miss" from the dropdown, the email when received will always have "Mr" as the title.
Here is the mailer that is the action for the form when 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('mail@mail.co.uk', 'Site');
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
?>
The $_POST['title']
above is where i am having the problem. How can i change the code so that the correct select option is sent from the users input?
It turns out this was a stupid mistake where there were conflicting input name/IDs.
ID title
was assigned to another element on my form witch was causing the conflict.