|
-
Oct 26th, 2006, 07:54 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Really easy PHP email question
Hi this is easy but I've forgotten it and can't find the answer!
I have a form used to email and I have a combobox on my page.
What I want to do is change the subject of my email depending on what the user selects on the combobox - how do I do this again???
Heres my PHP:
Code:
<?PHP
$to = "[email protected]";
$subject = "Martin Page";
$message = "Name: " . $name;
$message .= "\nEmail: " . $email;
$message .= "\n\nMessage: " . $message;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$sentOk = mail($to, $subject, $message, $headers);
?>
Any help folks?
-
Oct 26th, 2006, 07:58 AM
#2
Re: Really easy PHP email question
HTML Code:
<select name="subject">
<option value="Example Subject">Example Subject</option>
</select>
PHP Code:
$subject = $_POST['subject'];
Although you should validate the subject against the list again, otherwise a h4x0r could use send anything.
So, better:
PHP Code:
<?php
$subjects = array(
'meat',
'vegetables'
);
?>
[...]
<select name="subject">
<?php foreach($subjects as $subject): ?>
<option value="<?php echo $subject ?>"><?php echo $subject ?></option>
<?php endforeach; ?>
</select>
[...]
and when sending the email:
PHP Code:
$subject = in_array($_POST['subject'], $subjects) ? $subject : 'No or invalid subject specified';
Last edited by penagate; Oct 26th, 2006 at 08:02 AM.
-
Oct 26th, 2006, 08:09 AM
#3
Thread Starter
Hyperactive Member
Re: Really easy PHP email question
Excellent thanks for that!
-
Oct 26th, 2006, 08:10 AM
#4
Thread Starter
Hyperactive Member
Re: Really easy PHP email question
Oh no - problem I got a 405 error lol
Sorry I fixed that it was the wrong page lol;
In the emails I receive I get 'from' and then something like [email protected] etc - can I change it to show the exact email written in the email field??
Last edited by wwwfilmfilercom; Oct 26th, 2006 at 08:13 AM.
Reason: My mistake...
-
Oct 26th, 2006, 08:12 AM
#5
Re: Really easy PHP email question
My good gracious goodness (or something).
when do you get that?
-
Oct 26th, 2006, 08:13 AM
#6
Thread Starter
Hyperactive Member
Re: Really easy PHP email question
Sorry please see my edit above oops..
-
Oct 26th, 2006, 08:17 AM
#7
Re: Really easy PHP email question
$headers = "From: $theEmail ($name)\n";
-
Oct 26th, 2006, 08:21 AM
#8
Thread Starter
Hyperactive Member
Re: Really easy PHP email question
Awesome, all works fine - thanks for your help! Appreciated!!
-
Oct 26th, 2006, 08:23 AM
#9
Re: Really easy PHP email question
No worries.
Don't forget to mark your thread resolved from the Thread Tools menu above the first post, or the moderators will come and eat you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|