[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? :thumb:
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';
Re: Really easy PHP email question
Excellent thanks for that!
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??
Re: Really easy PHP email question
My good gracious goodness (or something).
when do you get that?
Re: Really easy PHP email question
Sorry please see my edit above oops..
Re: Really easy PHP email question
$headers = "From: $theEmail ($name)\n";
Re: Really easy PHP email question
Awesome, all works fine - thanks for your help! Appreciated!!
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.