Search code examples
phpfetchsubjectmail-form

Fetch part of url to make subject of mail


I have just received a great answer to my previous question: LINK

In addition to this answer, I have a new challenge.

My mailform is supported with a form.lib.php file where the mailsubject is defined and printed to the mail.

 define( 'PHPFMG_SUBJECT' , "" );


 function    sendFormMail( $form_mail, $sFileName = ""  ) 
{ 
$to        = filterEmail(PHPFMG_TO) ;
$cc        = filterEmail(PHPFMG_CC) ;
$bcc       = filterEmail(PHPFMG_BCC) ;

}; 

 $subject   = PHPFMG_SUBJECT ; 

The vacancy number that we fetched in my previous topic, should be printed as the mail subject, so my crm system is using it to registrate the response.

How can I make this happen?


Solution

  • Your solution is not working yet. I tried to copy the $vacancies into the subject define field, but then the subject of the mail is empty.

    I have two files, one mailform and one form.lib.

    In the mailform I have this code:

     <input type="hidden"style="font-weight:bold" formmethod="POST" name="field_5"  id="field_5" value=" <php  str="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     $arr=explode("-",$str); $vacancynumber=end($arr); echo end($arr); ?>" 
    

    This makes that this field is indeed showing the vacancy number in the mail that is send. But now I have to make this number in the subject too...

    The .lib file is showing this (it shows more, but I think this is the relevant code):

    <?php define( 'PHPFMG_SUBJECT' , "" );?>
    
         <?php
    $msg = ob_get_contents() ;
    ob_end_clean();
    return trim($msg);}
      $GLOBALS['form_mail'] = array();
     $GLOBALS['form_mail']['field_0'] = array( "name" => "field_0", "text" => "Voornaam",  "type" => "senderfirstname", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_1'] = array( "name" => "field_1", "text" => "Achternaam",  "type" => "senderlastname", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_2'] = array( "name" => "field_2", "text" => "E-mail",  "type" => "sender's email", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_3'] = array( "name" => "field_3", "text" => "(Mobiel) Telefoonnummer",  "type" => "text", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_4'] = array( "name" => "field_4", "text" => "Woonplaats",  "type" => "text", "instruction" => "", "required" => "Required" ) ;
    
    $GLOBALS['form_mail']['field_5'] = array( "name" => "field_5", "text" => "Vacaturenummer",  "type" => "text", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_7'] = array( "name" => "field_7", "text" => "Upload je CV",  "type" => "attachment", "instruction" => "", "required" => "Required" ) ;
    $GLOBALS['form_mail']['field_8'] = array( "name" => "field_8", "text" => "Akkoord privacy",  "type" => "checkbox", "instruction" => "", "required" => "" ) ;
    $GLOBALS['form_mail']['field_9'] = array( "name" => "field_9", "text" => "Hoe heb je ons gevonden?",  "type" => "checkbox", "instruction" => "", "required" => "Required" ) ;?>
    
    
    function    sendFormMail( $form_mail, $sFileName = ""  ) 
    { 
    $to        = filterEmail(PHPFMG_TO) ;
    $cc        = filterEmail(PHPFMG_CC) ;
    $bcc       = filterEmail(PHPFMG_BCC) ;
    
    // simply chop email address to avoid my website being abused
    if( false !== strpos( strtolower($_SERVER['HTTP_HOST']),'formmail-maker.com') ){
        $cc   = substr($cc, 0, 50);
        $bcc = substr($bcc,0, 50);
    };    
    
    
    $subject   = PHPFMG_SUBJECT ; 
    $from      = $to ;
    $fromName  = "";
    $titleOfSender = '';
    $firstName  = "";
    $lastName  = "";
    
    $strip     = get_magic_quotes_gpc() ;
    $content   = '' ; 
    $style     = 'font-family:Verdana, Arial, Helvetica, sans-serif; font-size : 13px; color:#474747;padding:6px;border-bottom:1px solid #cccccc;' ;
    $tr        = array() ; // html table
    $csvValues = array();
    $cols      = array();
    $replace   = array();
    $RecordID  = phpfmg_getRecordID();
    $isWritable = is_writable( dirname(PHPFMG_SAVE_ATTACHMENTS_DIR) );
    
    foreach( $form_mail as $field ){
        $field_type = strtolower($field[ "type" ]);
        if( 'sectionbreak' == $field_type ){
            continue;
        };
    
        $value    = trim( $_POST[ $field[ "name" ] ] ); 
        $value    = $strip ? stripslashes($value) : $value ;
        if( 'attachment' == $field_type ){
            $value = $isWritable ? phpfmg_file2value( $RecordID, $_FILES[ $field[ "name" ] ] ) : $_FILES[ $field[ "name" ] ]['name'];
            //$value = $_FILES[ $field[ "name" ] ]['name'];
        };
    
        $content    .= $field[ "text" ] . " \t : " . $value .PHPFMG_LNCR;
        $tr[]        = "<tr> <td valign=top style='{$style};width:33%;border-right:1px solid #cccccc;'>" . $field[ "text" ] . "&nbsp;</td> <td valign=top style='{$style};'>" . nl2br($value) . "&nbsp;</td></tr>" ;  
        $csvValues[] = csvfield( $value );
        $cols[]      = csvfield( $field[ "text" ] );
        $replace["%".$field[ "name" ]."%"] = $value;
    
        switch( $field_type ){
            case "sender's email" :
                $from = filterEmail($value) ;
                break;
            case "sender's name" :
                $fromName = filterEmail($value) ;
                break;
            case "titleofsender" :
                $titleOfSender = $value ;
                break;
            case "senderfirstname" :
                $firstName = filterEmail($value) ;
                break;
            case "senderlastname" :
                $lastName = filterEmail($value) ;
                break;
            default :
                // nothing                  
        };