uaintgotthisid Posted January 23, 2009 Share Posted January 23, 2009 Hi all,I've got a mail form working. I want the "To" e-mail address to be selected dependant on the subject of the e-mail (selected via a dropdown box).I can get this to work if I have a HTML drop down with the Select values set as the e-mail addresses within this code but this isn't very secure.Hence I want to set the To value within my php file dependant on what the forms subject POSTS.I can't seem to get it to work and your help would be appreciated.Cheers all if ($subject == General) 'my@email.com'; elseif ($subject == Quotation) 'my@email.com'; elseif ($subject == Customer Care) 'my@email.com'; Link to comment Share on other sites More sharing options...
jeffman Posted January 23, 2009 Share Posted January 23, 2009 You need some assignment statements in there, and then the variable you use gets fed to your mail() function. (And remember your quote marks.) if ($subject == 'General') $to = 'my@email.com'; elseif ($subject == 'Quotation') $to = 'my@email.com'; elseif ($subject == 'Customer Care') $to = 'my@email.com';###$result = mail($to, etc); Link to comment Share on other sites More sharing options...
uaintgotthisid Posted January 24, 2009 Author Share Posted January 24, 2009 Top man thanks very much Link to comment Share on other sites More sharing options...
uaintgotthisid Posted February 19, 2009 Author Share Posted February 19, 2009 $to = if ('subject' == 'General Enquiry') $to = 'email@email.com'; elseif ('subject' == 'Quotation') $to = 'email@email.com'; elseif ('subject' == 'Customer Care') $to = 'email@email.com'; I'm still playing with this and can't get it to work the HTML end has a dropdown box has the name "subject", and it's options values are set to "General Enquiry" etc. It's saying unexpected T_IF Link to comment Share on other sites More sharing options...
Synook Posted February 19, 2009 Share Posted February 19, 2009 Web Guy, your first "$to = " is causing problems. See why? Also, "subject" won't equal "General Enquiry", think about it. You had it right the first time!Also, a switch() statement may be more useful in this case. http://www.php.net/manual/en/control-structures.switch.php Link to comment Share on other sites More sharing options...
uaintgotthisid Posted February 23, 2009 Author Share Posted February 23, 2009 $subject = $_POST['subject'];$from = $_POST['from'];$name = $_POST['name'];$number = $_POST['number'];if ('subject' == 'General Enquiry') $to = 'mail@mail.com'; elseif ('subject' == 'Quotation') $to = 'mail@mail.com'; elseif ('subject' == 'Customer Care') $to = 'mail@mail.com'; so I've got this now, removed the first $to (right?)the General Enquiry thing I changed on the form so that it is correct. It's still sending me an error saying there are no e-mail addresses in the to field. Link to comment Share on other sites More sharing options...
uaintgotthisid Posted February 23, 2009 Author Share Posted February 23, 2009 switch ($subject) { case "General Enquiry": $to = 'mail@mail.com'; break; case "Quotation": $to = 'mail@mail.com'; break; case "Customer Care": $to = 'mail@mail.com'; break; //$to = 'mail@mail.com';$subject = $_POST['subject'];$from = $_POST['from'];$name = $_POST['name'];$number = $_POST['number']; I've also tried this one, but it doesn't work either. It tells me that the last ?> in my code is wrong for some reason. Link to comment Share on other sites More sharing options...
Synook Posted February 23, 2009 Share Posted February 23, 2009 I've also tried this one, but it doesn't work either. It tells me that the last ?> in my code is wrong for some reason.You missed a closing brace. With the if() version, you are trying to compare 'subject', when you actually want to compare $subject. Link to comment Share on other sites More sharing options...
uaintgotthisid Posted February 23, 2009 Author Share Posted February 23, 2009 $subject = $_POST['subject'];$subject = $_POST['subject'];$from = $_POST['from'];$name = $_POST['name'];$number = $_POST['number'];if ('$subject' == 'General') $to = 'mail@mail.com'; elseif ('$subject' == 'Quotation') $to = 'mail@mail.com'; elseif ('$subject' == 'Customer Care') $to = 'mail@mail.com'; Ok so now I've got $subject do I still need the 'quotes' ?It is still not working like this, so I need to put brackets around the if thing? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.