Results 1 to 4 of 4

Thread: email subject

  1. #1
    Frontpage User
    Join Date
    Feb 2010
    Posts
    15
    Post Thanks / Like

    Default email subject

    Hi all

    I was wondering if someone could help me with this. I have a php form script that handles the contact form on a website i have. The problem i have is that in my script the email subject is like this

    $emailSubject = 'Contact Form';

    Which means ( as i found out the annoying way ) that no matter who sends an email or how many is sent to me they all have the same thing in the subject field "Contact Form" , Everything else is fine Name etc.
    On the form, i have a drop down list that people can choose what the reason for their email is ( info, help, about, other etc. ) , so what i was wondering, instead of having "Contact Form" appear in the subject field that arrives in my emails ( gmail ) can i get the whatever topic they choose from the list to appear in the subject field of my emails ( it would make life so much easier ) , and if i can could anyone tell me the code i'd need to change. I presume it's not as simple as changing

    $emailSubject = 'Contact Form';
    to
    $emailSubject = 'list';

    I would be really thankful for any help with this.

    Paul

  2. #2
    Senior Member louie's Avatar
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,423
    Post Thanks / Like

    Default

    you can grab the value of the select menu in your form and attache it to the subject line:
    PHP Code:
    $emailSubject 'Contact Form'.(!empty($_POST['select_name']) ? " "$_POST['select_name'] : ""); 
    so that will show now as "Contact Form [Help, Info, or About]
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  3. #3
    Wannabe Geek php.allstar's Avatar
    Join Date
    Apr 2009
    Location
    Monamolin, Gorey, Co. Wexford
    Posts
    405
    Post Thanks / Like

    Default

    Just to add to louie's solution, you should also take care to prevent possible email header injection which can lead to your form being used as a mailer for spam bots etc...

    PHP Code:

    function sanitize$subject ) {
       return( 
    str_ireplace(array(  "Content-Type:","to:","cc:""bcc:""\n""\r""%0d""%0a"), ""$subject) );
    }

    $subject sanitize($_POST['select_name']);

    $emailSubject 'Contact Form'.(!empty($subject) ? " "$subject ""); 
    if you are using php less than php5, you'll have to use something like preg_replace as str_ireplace is a php5 only function, but lets hope you have php5 and I don't have to explain preg_repalce to you!
    Last edited by php.allstar; 12-04-2010 at 11:46 AM. Reason: Chubby fingers - syntax error - comma where it shouldn't be!

  4. #4
    Frontpage User
    Join Date
    Feb 2010
    Posts
    15
    Post Thanks / Like

    Default

    Louie and php.allstar

    You guys are legends, thanks a million for your help, it works like a charm now.

    All the best

    Paul

Similar Threads

  1. Subject: Business Database Dubai, Middle East
    By sehrishmus in forum General Chat
    Replies: 6
    Last Post: 19-02-2009, 09:09 PM
  2. Zanox Email?
    By blacknight in forum Affiliate Programs
    Replies: 3
    Last Post: 16-07-2008, 11:15 PM
  3. Email integration mod
    By blacknight in forum Forum Management
    Replies: 1
    Last Post: 11-01-2008, 07:03 AM
  4. Realex email
    By louie in forum Webmaster Discussion
    Replies: 5
    Last Post: 13-06-2007, 07:48 AM

Visitors found this page by searching for:

email subject dropdown

email form select menu adds to email subject

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •