格式化PHP多行字符串

时间:2017-12-06 14:49:23

标签: php wordpress email contact-form-7

我一直在尝试使用选择列表创建一个联系表单自动回复器,我使用的主要来源之一是this

我对他的代码所做的唯一改变显然是变量并且已经改变了

add_action( 'wpcf7_mail_sent', 'contact_form_autoresponders' ); 

add_action( 'wpcf7_mail_sent', array($this, 'contact_form_autoresponders' ), 5);

我一直在尝试为所选“选择”菜单中的所有选项创建自动电子邮件回复。

我一直在导入另一个file.php,其中包含我需要的所有字符串变量“<<

file.php中的所有变量如下所示:

$some_variable =<<<EOT multiple 
                    lines 
                     here
 EOT;

由于我的电子邮件回复是希伯来文,我希望将回复的邮件从右向左发送,我正在寻找一个方法将我的字符串对齐并添加一些URL标记,但无法找到它。

我尝试将它添加到Headers和String头部,但它对我来说没有用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" 
direction="rtl">

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

替换...

direction="rtl"

dir="rtl"

您可以在此处找到更多信息https://www.w3.org/International/questions/qa-html-dir

请记住也要更改lang属性。

答案 1 :(得分:0)

如果我理解正确,如果 file.php 包含过帐对象属性数组(即$this->option1$this->option2 )然后根据您提供的链接,代码看起来像:

#our autoresponders function
function contact_form_autoresponders( $contact_form ) {

    if( $contact_form->id==1234 ){ #your contact form ID - you can find this in contact form 7 settings

        #retrieve the details of the form/post
        $submission = WPCF7_Submission::get_instance();
        $posted_data = $submission->get_posted_data();                          

        $msg = array();
        #set autoresponders based on dropdown choice, in an array     
        switch( $this->posteddata){ #your dropdown menu field name
            case 'California':
            $msg+="California email body goes here";
            break;

            case 'Texas':
            $msg+="Texas email body goes here";
            break;

        }
        $msg_str = implode("", $msg);

        #mail it to them
        mail( $posted_data['your-email'], 'Thanks for your enquiry', $msg_str );
    }

}

请注意 $msg = array(); 作为字符串数组, $msg += "<multiline string>" 表示与发布的查询变量匹配的每个案例, $msg_str = implode("", $msg) 制作最终字符串(可能是HTML或非HTML)。

如果您使用的是 HTML电子邮件,请调整选项&#39;价值权利是 css规则的问题。所以你的最终HTML电子邮件看起来像是:

<html>
<head>
    <style>
        .align-right
        {
            text-align: right;
            direction: rtl;
        }
    </style>
</head>
<body>
...
...
...
<table>
    <tbody>
        <tr>
        <td class="option-name">California</td>
        <td class="option-value align-right">THE MULTILINE STRING</td>
        </tr>
        <tr>
        <td class="option-name">Texas</td>
        <td class="option-value align-right">THE MULTILINE STRING</td>
        </tr>
    </tbody>
</table>
</html>
相关问题