0

提交表单时,我正在从 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 的变量。不幸的是,收到电子邮件后,该链接不起作用。有谁知道如何解决这一问题?

4

2 回答 2

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>';   
?>
于 2016-01-06T19:55:53.150 回答
1

对您的问题的最简单答案是将标签放在您的<?php>标签周围,如下所示:$google_map<a>

<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 电子邮件,则需要定义比此处列出的更多的参数。这是一个改编自网络教程 HTML 电子邮件的基本示例,它应该让您大致了解如何在 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.';
  }
?>
于 2016-01-06T22:10:12.340 回答