10979 Posts in 2722 Topics by 1815 members
|Go to End|
1 December 2010 at 11:37pm
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.
2 December 2010 at 12:10am
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.
$name = "Subject",
$title = "Contact Subject",
$source = array(
"firstname.lastname@example.org" => "Report a Student Absence",
"email@example.com" => "Contact the Head's PA",
"firstname.lastname@example.org" => "Problem with Fronter/VLE",
"email@example.com" => "Contact a Member of Staff",
"firstname.lastname@example.org" => "General Enquiry",
"email@example.com" => "Problem with Parentmail",
"firstname.lastname@example.org" => "Other",
2 December 2010 at 12:29am
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?
along these lines maybe?
if ('Subject' == "Other");
Would this approact work better / at all?
Thanks for advice.
2 December 2010 at 2:05am
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.
Hope that helps.
2 December 2010 at 4:05am
Wow, wasn't expecting it to be done for me, but that deserves a massive thanks... so THANKS
|Go to Top|