2016-01-06 74 views
0

我在提交表單時發送WordPress的交易HTML電子郵件。例如,電子郵件中包含人員姓名等信息,但我也希望在電子郵件中添加鏈接到谷歌地圖。將WordPress地圖鏈接添加到由WordPress發送的交易電子郵件中

鏈接例如:

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的變量。不幸的是,收到電子郵件時鏈接不起作用。有誰知道如何解決這一問題?

+0

證明建立電子郵件的代碼,請.. – scaisEdge

回答

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>'; 
?> 
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電子郵件發送給自己,你需要定義更多參數比你在這裏列出的要多。這個改編自web tutorial HTML email一個基本的例子應該給你如何在PHP格式化HTML電子郵件一般意義:

<?php 
    // Setup sending address parameters for eventual php mail() call 
    $to = '[email protected]'; 
    $subject = 'Email Update About XYZ'; 
    $from = '[email protected]'; 

    // 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.'; 
    } 
?>