Developer Support »

Email subject

This applies to both scripts, FormToEmail and FormToEmail-Pro

With both scripts the email subject is hard-coded into the script (it's a configurable option with the Pro version). This is the subject that is in the subject line of the email that is sent to you from the script.

You might want your visitor to select a subject from a list on your form and for this chosen subject to be the subject line of the email that the script sends you (see below if you want the visitor to enter their own subject line). This can be achieved by following these steps:

In the first instance you will need to put the HTML code on your form to offer your visitor a choice of subject lines to choose from. Typically you might use code like this:

<select name="subject">
<option value="default subject">Select a subject</option>
<option>Product A</option>
<option>Product B</option>
<option>Product C</option>
</select>

Next you need to change the code in the script to process the subject input. Open up the script (FormToEmail.php or formtoemailpro.php) in a text editor. Locate the relevant line in the script:

For FormToEmail:
$subject = "FormToEmail Comments";

For FormToEmail-Pro:
$subject = "Comments from contact form";

Change the line to this:

$subject = $_REQUEST['subject'];

That's it. Save the file and upload it to your webspace together with your form page with the new code on it.

Some points. In the example above the name "subject" has been used for the form input. You can use any name you like but you must also change the line in the script to match it, so if you had <select name="email_subject"> then the line in the script would be $subject = $_REQUEST['email_subject'];

You will get the subject line showing up in the body of the email. If using the free script you will have to put up with this (might even be useful). If you are using the Pro script you can ignore the subject input by naming it in the fields to ignore configuration option. You can also use an email template and leave out the subject input from the body of the email.

Using the code above, if your visitor does not select a subject, the email will show the subject "default subject". You can change this to suit. If you require your visitor to select a subject then with the Pro version of the script, you can make this a required field.

User-entered subject line
If you would like your visitor to enter their own subject line for the email, you can put an input field on your form like this:

<input type="text" name="subject">

Then change the line in the script (as described above) to this:

$subject = $_REQUEST['subject'];

Using form values in the subject line
You can use any of the submitted form values in the subject line. This example will show the visitor's name in the subject:

$subject = "Quotation request from " . $_REQUEST['name'];

This shows a first and last name:

$subject = "Quotation request from " . $_REQUEST['first_name'] . " " . $_REQUEST['last_name'];

Note, in the above line " " puts a space between the first name and the last name. This assumes you have the inputs 'first_name' and 'last_name' on your form.

This example will show a form value as the subject line without any additional text:

$subject = $_REQUEST['some_form_value'];

Replace 'some_form_value' with the name of the form field you want to use.

As before, the names in the quotes are the names of your form fields and must be exactly as they appear on your form.