Hi guys,
I'm trying to work this out on my own, but I'm running out of time to figure this out and my PHP skills are newbie level.
Here's the deal, I'm creating a contact form that has a drop down box with multiple contacts. I tested to make sure that I can send an actual email to my email address, so that's no problem. It worked just fine after going through hoops of getting that to work. The issue is that it was only 1 email address. I need this to work for multiple email addresses.
This is the test code I was using:
<?php
$msg="";
if(isset($_POST['submit']))
{
$from_add = "
[email protected]";
$to_add = "
[email protected]";
$subject = "Test Subject";
$message = "Test Message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
/*?> [mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from =
[email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =<?php */
if(mail($to_add,$subject,$message,$headers))
{
$msg = "Mail sent OK";
}
else
{
$msg = "Error sending email!";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test form to email</title>
</head>
<body>
<?php echo $msg ?>
<p>
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
</form>
</p>
</body>
</html>
Now I was thinking that I would just be able to add the email array to $to_add using something like this, but clearly I'm messing up because it keeps displaying the error before I even hit the submit button:
<?php
$msg="";
if(isset($_POST['submit']))
{
$from_add ='
[email protected]'
$to_add = array('choice 1' => '
[email protected]', 'choice 2' =>
[email protected]');
$subject = "Test Subject";
$message = "Test Message";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
/*?> [mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from =
[email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =<?php */
if(mail($to_add,$subject,$message,$headers))
{
if(array_key_exists($_POST['dropdown']))
{
$msg = "Mail sent OK";
}
}
else
{
$msg = "Error sending email!";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test form to email</title>
</head>
<body>
<?php echo $msg ?>
<p>
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
<select name='dropdown' method="post">
<option value=''>Please Choose Dept.</option>
<option value='choice 1'>Boating</option>
<option value='choice 2'>Camping</option>
</select>
<input type='submit' name='submit' value='Submit'>
</form>
</p>
</body>
</html>
Can someone help me out with this please?