PDA

View Full Version : PHP Mail with Selection Box?



VersusMG
December 13th, 2005, 11:34 AM
I am creating a contact form that has different subject options:

Sponsorship Information
Member Information
Marketing Information
Sales and Advertising
Website Question
Other

What I need to happen is to have the message be sent to a different person depending on which selection is made.

This is what I tried...I just moves to the bottom 'if' statement and send to that address.


<?php

// get the variables from the URL request string
$name = $_REQUEST['name'];
$company = $_REQUEST['company'];
$email = $_REQUEST['email'];
$ssubject = $_REQUEST['subject'];
$comments = $_REQUEST['comments'];

// Variables for who's email it should go to:
if($ssubject = "Sponsor Information") {
$mailto = "setha@comporium.net";
}
if($ssubject = "Member Information") {
$mailto = "saldridge@yeacharlotte.org";
}
if($ssubject = "Marketing Information") {
$mailto = "seth@sethaldridge.com";
}
else($mailto = "setha@comporium.net");

// Send the email to me!
$to = "$mailto";
$subject = "$ssubject";
$body = "The following is a message from YEA Charlotte's website.\n\nName: $name\nCompany: $company\nEmail: $email\n\nComments: $comments\n\nPlease respond to this message as soon as possible.\n\nThank you,\nAdmin\nwww.YEACharlotte.org";
$from = "FROM: $email";
$response = mail($to, $subject, $body, $from);

// If the email successfully sends go to header, else show message!
if($response)
{
header("location: http://www.yeacharlotte.org/contacts.html");
}
else
{
echo("Message was not able to send!");
}

?>

Ankou
December 13th, 2005, 01:45 PM
I just glanced at the code but I noticed your if statements should have "==" not "=" -- so it should be:

if($ssubject == "Sponsor Information") {
$mailto = "setha@comporium.net";
}

(Change the other if statements as well for checking the value of $ssubject)


You could also use if/else if/else for checking $ssubject.

VersusMG
December 13th, 2005, 02:17 PM
I knew it was going to be something small that I missed. The good news is i'm getting better!

:)

Thanks!

Ankou
December 13th, 2005, 06:12 PM
No problem.

I read a tip some place that said you should put your conditional staments with the variable second.... like:

if("some text" == $foo){ ...}

That way if you slip up and put:

if("some text" = $foo){ ...}

You get an error instead of actually assigning the variable a value.