Dynamic Subject Line in PHP Form

I’ve created a form in Adobe Muse - which only allows for a static form name, which appears to be stored in an associative array named form in a PHP file. I am wondering if it is possible to edit the code to make the Subject line (Row 13) dynamic, where it will equal the date and time that the form was submitted, instead of the static text string ‘New Form Submission’?

Here is some of the PHP code (I didn’t copy the complete file, but most of what you probably need to see)

Thanks in advance for your help!

[php]<?php
/*
If you see this text in your browser, PHP is not configured correctly on this hosting provider.
Contact your hosting provider regarding PHP configuration for your site.

PHP file generated by Adobe Muse CC 2015.2.0.352
*/

require_once(‘form_process.php’);

$form = array(
‘subject’ => ‘New Form Submission’,
‘heading’ => ‘New Form Submission’,
‘success_redirect’ => ‘’,
‘resources’ => array(
‘checkbox_checked’ => ‘Checked’,
‘checkbox_unchecked’ => ‘Unchecked’,
‘submitted_from’ => ‘Form submitted from website: %s’,
‘submitted_by’ => ‘Visitor IP address: %s’,
‘too_many_submissions’ => ‘Too many recent submissions from this IP’,
‘failed_to_send_email’ => ‘Failed to send email’,
‘invalid_reCAPTCHA_private_key’ => ‘Invalid reCAPTCHA private key.’,
‘invalid_field_type’ => ‘Unknown field type ‘%s’.’,
‘invalid_form_config’ => ‘Field ‘%s’ has an invalid configuration.’,
‘unknown_method’ => ‘Unknown server request method’
),
‘email’ => array(
‘from’ => ‘[email protected]’,
‘to’ => ‘[email protected]
),
‘fields’ => array(
‘custom_U118’ => array(
‘order’ => 1,
‘type’ => ‘string’,
‘label’ => ‘Name’,
‘required’ => true,
‘errors’ => array(
‘required’ => ‘Field ‘Name’ is required.’
)
),
‘Email’ => array(
‘order’ => 2,
‘type’ => ‘email’,
‘label’ => ‘Email’,
‘required’ => true,
‘errors’ => array(
‘required’ => ‘Field ‘Email’ is required.’,
‘format’ => ‘Field ‘Email’ has an invalid email.’
)
),
‘custom_U104’ => array(
‘order’ => 3,
‘type’ => ‘string’,
‘label’ => ‘Company’,
‘required’ => true,
‘errors’ => array(
‘required’ => ‘Field ‘Company’ is required.’
)
),
‘custom_U123’ => array(
‘order’ => 4,
‘type’ => ‘string’,
‘label’ => ‘Work Address’,
‘required’ => true,
‘errors’ => array(
‘required’ => ‘Field ‘Work Address’ is required.’
)[/php]

Try:

‘subject’ => ‘New Form Submission’ . date(“Y-m-d H:i:s”);

This will give you the current date/time in the format of 2016-06-28 12:33:22 or whatever.
You can alter the formatting as needed. For slashes: date(“Y/m/d H:i:s”);
Many other ways to display it if needed…

Thanks Ernie,

But that did not appear to work - when I hit the “submit” button, we get an error saying “The server has encountered and error”, and it fails to email the form.

Did you try it with the dashes or slashes. It might be a problem with using the slashes…

One other thought… You might want to try dumping the array to see what is being stuck into it for the subject.
Just before emailing is done, dump it using print_r($form); and die(“
temporary dump!”); That will dump the $form
array and then die which will allow you to look at the live data just before the mail function fails. Look at the subject key
and see what is being stuck in there. It might explain the error…

Figured it out -

[php]‘subject’ => 'New Form Submission ’ . date(‘m/d/Y h:i:s a’, time()),[/php] worked for me

Thanks for your help Ernie!!!

Oh, forgot to ask you what kind of server you were on!

Great you solved it… CYA in the Bitstream…

Sponsor our Newsletter | Privacy Policy | Terms of Service