I am having some troubles and hope someone can enlighten me.
I have a contact form with a ListboxField. The user chooses an option and based on this option I need to send an email to different people with different subjects.
I have code here http://pastie.org/1337807
Currently the selection chooses the email reciepient but I am left with a generic subject - $email->setSubject('Website Contact');
Is there any way to have the email subject dynamically chosen aswell? Something like $email->setSubject($data['Subject']); - this obviously will set as the email address.
I'm probabbly approaching from the wrong direction.
Hope I have explained clearly.
Sure thing. You can simply add another TextField where you can enter the mail subject.
Your script is very insecure though. It can easily be abused to send mails from any address to any other address... that's going to be abused by spammers in no time.
You should at least check if the mail-to address is actually one from your dropdown... your PHP code seems kinda odd too. In the following snippet, the red parts are completely redundant.
Thanks for reply, I'm sure you can tell php isn't my forte. I consturcted this from other bits of code.
I'll look into the address check (any pointer where to start looking?)
The ListboxField was used as the subject choice. Adding another TextField to enter the subject takes away the point of having it in the first place.
Maybe if I attempt it from a different point and use the ListboxField to populate the email subject instead of the recipient (would this take away the insecurities?). How can I then select the email recipient based on the subject choice?
You could do this using if/else statements, but that's kinda cumbersome.
I changed your code to use another approach: http://pastie.org/1338190
In the code you can see, that the email => subject array is a private member of the class. We can now use this for A) populating the dropdown and B) validating the incoming e-mail address. In addition we can also use the array to look up the e-mail subject.