【问题标题】:Formatting a PHP multi line string格式化 PHP 多行字符串
【发布时间】:2018-05-20 12:00:03
【问题描述】:

我一直在尝试使用选择列表创建联系表单自动回复,我使用的主要来源之一是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">

任何帮助将不胜感激。

【问题讨论】:

  • 如果您在邮件消息的上下文中询问,试试这个:stackoverflow.com/a/20680966/2962442
  • 在您的修改中,您将传递的第二个参数STRING 替换为ARRAY。 add_action 函数准备好处理了吗?
  • @kmlnvm 我在需要翻译成电子邮件的字符串上下文中询问
  • @Yonihodefi 我认为这取决于您的 IDE,例如:jetbrains.com/help/phpstorm/configuring-text-direction.html 但请记住,当您发送电子邮件以更改 html 或 css 中文本的方向时。
  • @Yonihodefi 我不知道 rtl 是否适用于英语

标签: php wordpress email contact-form-7


【解决方案1】:

替换...

direction="rtl"

dir="rtl"

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

记得也要更改 lang 属性。

【讨论】:

    【解决方案2】:

    如果我对您的理解正确,如果您的 file.php 包含 已发布对象属性的数组(即 $this-&gt;option1$this-&gt;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 += "&lt;multiline string&gt;" 用于匹配发布的查询变量的每个案例,以及 $msg_str = implode("", $msg) 生成最终字符串(可能是 HTML 或非 HTML)。

    如果您使用的是HTML 电子邮件,则正确对齐选项值是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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2018-05-22
      • 2018-08-12
      • 2016-02-24
      • 1970-01-01
      • 2021-10-24
      相关资源
      最近更新 更多