Menu

How Do I Place Multiple Fields in EMail Subject Line?

Help
2014-06-16
2014-06-17
  • Scott Halligan

    Scott Halligan - 2014-06-16

    First off, many thanks for a great form generator. I made my first today, and from studying various posts I've been able to customize it to my liking with one exception.

    I did learn how to take one of the form's fields and place it in the subject line of the generated email, but in my case I'd like to be able to have multiple fields entered as a subject. I can't seem to figure out how to do that or I've overlooked it.

    Thanks very much, and regards.

    Scott
    Webmaster - Scan New England
    http://www.scan-ne.net

     
    • TNTEverett

      TNTEverett - 2014-06-16

      Using example #2 on this link allows you to do most anything you want. If you still need help let me know.
      http://www.php.net//manual/en/function.mail.php

       
  • Chris Burnworth

    Chris Burnworth - 2014-06-16

    what kind of fields are you trying to combine into the subject line?

     
  • Scott Halligan

    Scott Halligan - 2014-06-16

    Hi Chris,

    Thanks for replying.

    I'm looking to have a total of three fields appear in the subject line, all of which are single line text fields. The form will be used to send incident notifications of breaking major public safety events, so the idea would be to have the subject look something similar to:

    MA-Boston-Major Motor Vehicle Crash

    And then of course the body of the message contains the information as generated by the form. I can make it work obviously with one field, just can't figure out the syntax for multiples.

    Thanks,

    Scott

     
  • TNTEverett

    TNTEverett - 2014-06-16

    Using the same example #2 from my previous post.
    $subject=$field1.' '.$field2.' '.$field3

     
  • Scott Halligan

    Scott Halligan - 2014-06-17

    Thanks! I missed your first post for some reason, Everett. The post from Chris was there; for some reason I didn't see yours. I'd like to think it was something other than operator error, but maybe not. :)

    I'll give this a shot; I appreciate the response.

     
  • Scott Halligan

    Scott Halligan - 2014-06-17

    Well, that didn't work. Copying and pasting what you have above and changing the fields to the order I want them results in this when I submit the form:

    Parse error: syntax error, unexpected 'session_start' (T_STRING) in /homepages/xx/xxxxxxxxxx/htdocs/notifications/processor.php on line 9

    Line 9 in my processor.php file is:

    session_start();

    And unfortunately, and again probably because I'm inexperienced, I'm not getting the correlation between your listed example #2 at your link and what I'm trying to accomplish.

    Thanks,

    Scott

     
  • TNTEverett

    TNTEverett - 2014-06-17

    That error is typically an error in a variable name. Make sure you do not try to use variable names that start with numbers. Also the line I gave as an example needs to be terminated with ;

     
  • Scott Halligan

    Scott Halligan - 2014-06-17

    Even I should have noticed I had the ; missing. No error now, but no subject either! I was emailed the form but the subject line was blank.

    No variable names starting with #'s in there.

    As my fields are field_1, field_2, etc should I duplicate that in the subject line instead of field1, field2, etc.

    Thanks.

     
  • Scott Halligan

    Scott Halligan - 2014-06-17

    I tried it both ways, field1 and field_1 and it made no difference. Blank subject each time.

    The only way I'm making it work thus far with a single field is this way, which I found elsewhere in these forums:

    $subject=$_POST['field_1'];

     
  • TNTEverett

    TNTEverett - 2014-06-17

    I have no idea what your form looks like and therefore my example was just that, an example. If your field names are $field_1 $field_2 $field_3 then yes absolutely you need to change my example.
    $subject=$field_1.' '.$field_2.' '.$field_3;
    or whatever the field names are for the values you want to apply to the subject in the correct order. You may also want to handle blank values so you don't double space. This is your form and only you know what to expect.

     
  • TNTEverett

    TNTEverett - 2014-06-17

    If you had this before
    $subject=$_POST['field_1'];
    Then you should start with
    $field1=$_POST['field_1'];
    or you should use
    $subject=$_POST['field_1'].' '.$_POST['field_2'].' '.$_POST['field_3'];
    My suggestion would be to use the first option and to check values to be what you expect before you apply them to a subject in an email. You want to prevent people from creating emails with arbitrary values that may be used to generate spam using your account.

     
  • Scott Halligan

    Scott Halligan - 2014-06-17

    Thanks for your help and patience. Finally got the second option to work, so that's a start. Getting those apostrophes in the right order was my problem.

    I'll work on the more secure option. This form, when I have it working to my liking, will be accessible only via a password protected folder which may help somewhat with keeping out the riff raff.

    Again, many thanks.

    Scott

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.