Results 1 to 9 of 9

Thread: [RESOLVED] Really easy PHP email question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Resolved [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?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Really easy PHP email question

    Excellent thanks for that!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    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...

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Really easy PHP email question

    My good gracious goodness (or something).

    when do you get that?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Really easy PHP email question

    Sorry please see my edit above oops..

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Really easy PHP email question

    $headers = "From: $theEmail ($name)\n";

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: Really easy PHP email question

    Awesome, all works fine - thanks for your help! Appreciated!!

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width