【问题标题】:Fetch part of url to make subject of mail获取部分 url 以作为邮件主题
【发布时间】:2015-02-17 17:36:40
【问题描述】:

我刚刚收到了对我之前问题的一个很好的回答:LINK

除了这个答案,我还有一个新的挑战。

form.lib.php 文件支持我的邮件表单,其中定义了邮件主题并将其打印到邮件中。

 define( 'PHPFMG_SUBJECT' , "" );


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

}; 

 $subject   = PHPFMG_SUBJECT ; 

我们在上一个主题中获取的空缺号码应该打印为邮件主题,因此我的 crm 系统正在使用它来注册回复。

我怎样才能做到这一点?

【问题讨论】:

    标签: php fetch subject mail-form


    【解决方案1】:

    如果我正确地阅读了您当前的问题。使用您在上一个问题中接受的答案,您需要执行类似的操作。

    $str = "www.test.com/director-sales-120";
    $arr=explode("-",$str);
    $vacancies = $arr[2];
    
    define( 'PHPFMG_SUBJECT' , "We have $vacancies vacancies" );
    

    查看您提供的功能。它实际上什么也没做,只是设置了一些局部变量。因此,如果此答案不起作用,我们可能需要查看该函数的更多代码。

    【讨论】:

    • 我的评论文字太多,请在下面查看我的答案。
    【解决方案2】:

    您的解决方案尚未奏效。我试图将 $vacancies 复制到主题定义字段中,但是邮件的主题为空。

    我有两个文件,一个 mailform 和一个 form.lib。

    在邮件表单中我有这个代码:

     <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); ?>" 
    

    这使得该字段确实显示了发送邮件中的空缺号码。但是现在我也必须在这个主题中提出这个数字......

    .lib 文件显示了这一点(它显示更多,但我认为这是相关代码):

    <?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                  
        };
    

    【讨论】:

    • 第一行将该变量设置为""。当您使用define() 时,您将变量声明为常量。一旦你的第一行执行,你将常量设置为一个空字符串,从那时起不能改变。我也看不到您在哪里尝试使用我上面发布的代码
    • 您好 Jacob,我已经删除了您发布的代码,抱歉,因此在上面的示例中不可见。我试过这样:
    • 您好 Jacob,可以使用什么来代替 define() 使其可变?对不起,在 php 领域不太好;)
    • 已解决:因为我已经在邮件表单中找到了空缺号码,所以我只需要在定义的主题中添加这个$GLOBALS['form_mail']['field_5'] = array( "name" =&gt; "field_5", "text" =&gt; "Vacaturenummer", "type" =&gt; "text", "instruction" =&gt; "", "required" =&gt; "Required" ) ;。解决方案:define( 'PHPFMG_SUBJECT' , $_POST['field_5']."" );
    猜你喜欢
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多