Dynamic Subject Field

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Wed Mar 21, 2012 7:23 am

Dynamic Subject Field

Postby RossM » Wed Mar 21, 2012 7:35 am

Hi all,

Bit of a php newbie but getting there !

I have a form which works fine so far. However I would like to make the subject of the email change according to a particular field. Example:

The form has 10 fields, 9 of which must be filled in (have Javascript validation on these that is working ok). The 10th field - a textbox - determines the subject of the email. ie If that field is left blank the email subject is X whereas if something is entered into that box, the email subject is Y. It doesn't matter what is entered or anything like that.

Any advice gratefully received.

User avatar
php-forum Active User
php-forum Active User
Posts: 335
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Dynamic Subject Field

Postby freshnet » Thu Mar 22, 2012 2:45 pm

If your field is called field10 you'll want something like this

Code: Select all

if (!isset($_POST['field10'])||$_POST['field10']=='')
{$subject = 'x';}
{$subject = $_POST[field10'];}

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 3 guests