NewB
NewB

Reputation: 125

PHP: email subject

I have a form on an intranet and when someone fils out the form it sends an internal email to a certain department.
I'm trying to get one of arrays to populate into the subject line but just can't figure out how.

The way I populate the array into the body which works fine is as follows:

<?php
    # .. snip ..
    $message = $message.'<tr>
    <td colspan="4" valign="top" class="style7">&nbsp;</td>
    </tr>';                                                                                                                     
    for($i = 0; $i < count($arrEncoding); $i++) {
        $desc= $arrEncodingDesc[$i];    
        $value= $arrEncoding[$i];                                                         
        if ($_POST[$arrEncoding[$i]]) {                                  
            $message = $message.'<tr><td colspan="4" valign="top" class="style4">'.$desc.'</td></tr>';                               
        }
    }
    # .. snip ..
?>

I tried a number of ways and below is just an example of one of the ways I've tried it:

$subject = $message.'Event Request Form:'.$arrEncoding[$i];

So basically I need the array of arrEncoding to populate into the subject field.
Any help would be greatly appreciated. I don't know if my question is concise enough, I'm still very much a beginner to the whole php world.

Upvotes: 0

Views: 190

Answers (1)

Carlos Lima
Carlos Lima

Reputation: 4172

As a quick answer, you probably want something like this:

<?php
    $_POST = array('BuiltIn'=>1,'SelfEncode'=>1); #Sample data :-)
    $arrEncoding = array("BuiltIn", "Hosted", "SelfEncode");

    $submitted_ids = array_filter($arrEncoding, function($id){ return isset($_POST[$id]); });
    $subject = "We got email about: " . implode(' ', $submitted_ids);
    print $subject;
?>

Please, note that the anonnymous function syntax used here requires php 5.3.0+

Upvotes: 1

Related Questions