【问题标题】:Add google maps link in a transactional email sent by WordPress在 WordPress 发送的交易电子邮件中添加谷歌地图链接
【发布时间】:2016-04-10 23:24:07
【问题描述】:

提交表单时,我从 WordPress 发送了一封事务性 HTML 电子邮件。例如,电子邮件包含人名等信息,但我还想在电子邮件中添加指向谷歌地图的链接。

链接示例:

https://www.google.co.uk/maps/place/London/@51.528308,-0.3817765,10z/data=!3m1!4b1!4m2!3m1!1s0x47d8a00baf21de75:0x52963a5addd52a99

<a> 示例:

<a target="_blank" href=" ' . $google_map . ' " style="color:#267ec8; font-size:14px; line-height:22px; font-weight:normal" color="#267ec8"><span style="color:#267ec8; font-size:14px; line-height:22px; font-weight:normal">See map</span></a>

$google_map 是包含由 WP 后端动态添加的谷歌地图 URL 的变量。不幸的是,收到电子邮件后,该链接不起作用。有谁知道如何解决这个问题?

【问题讨论】:

  • 请显示构建电子邮件的代码..

标签: wordpress google-maps hyperlink transactional-email


【解决方案1】:

如果可能,您应该格式化电子邮件正文的内容,添加类似这样的内容

<?php 

$google_map = 'https://www.google.co.uk/maps/place/London/@51.528308,-0.3817765,10z/data=!3m1!4b1!4m2!3m1!1s0x47d8a00baf21de75:0x52963a5addd52a99';

echo '<a target="_blank" href=" ' . $google_map . 
' " style="color:#267ec8; font-size:14px; line-height:22px; 
     font-weight:normal" color="#267ec8">
<span style="color:#267ec8; font-size:14px; line-height:22px;
  font-weight:normal">See map</span></a></td>';   
?>

【讨论】:

    【解决方案2】:

    对您的问题最简单的答案是将&lt;?php&gt; 标记放在$google_map 变量周围您的&lt;a&gt; 标记,如下所示:

    <a target="_blank" href="<?php echo $google_map; ?>">See map</span></a>
    

    我假设您已经在 PHP 文档的某处定义了该变量,但您不应该像这样将硬编码变量放入 WordPress 模板中。如果它是一个自定义字段并且这个 PHP 变量需要在 WordPress 循环中打印,那么解决方案看起来更像这样:

    <a target="_blank" href="<?php the_field('google_map_variable_input'); ?>">See map</span></a>
    

    如果您自己生成 HTML 电子邮件,则需要定义比此处列出的参数更多的参数。这是一个改编自web tutorial HTML email 的基本示例,它应该让您大致了解如何在 PHP 中格式化 HTML 电子邮件:

    <?php
      // Setup sending address parameters for eventual php mail() call
      $to = 'someone@example.com';
      $subject = 'Email Update About XYZ';
      $from = 'person@example.com';
    
      // To send HTML mail, the Content-type header must be set
      $headers  = 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
      // Create email headers
      $headers .= 'From: '.$user_email."\r\n".
          'Reply-To: '.$user_email."\r\n" .
          'X-Mailer: PHP/' . phpversion();
    
      // Create email body
      // Again, assumes $google_map is defined somewhere else
      $message = '<html><body>';
      $message .= '<a target="_blank" href="';
      $message .= $google_map;
      $message .= '" style="color:#267ec8; font-size:14px; line-height:22px; font-weight:normal" color="#267ec8"><span style="color:#267ec8; font-size:14px; line-height:22px; font-weight:normal">See map</span></a>';
      $message .= '</body></html>';
    
      // Send email
      if(mail($to, $subject, $message, $headers)){
          echo 'Your mail has been sent successfully.';
      } else{
          echo 'Unable to send email. Please try again.';
      }
    ?>
    

    【讨论】:

      猜你喜欢
      • 2014-05-30
      • 2015-10-13
      • 2011-05-18
      • 2015-05-20
      • 1970-01-01
      • 2021-05-09
      • 2016-11-25
      • 1970-01-01
      • 2012-05-25
      相关资源
      最近更新 更多