如何以最简单的方式在浏览器中添加打开的电子邮件,php,mailto

问题描述 投票:1回答:1

我正在从Webhook发送一封带有以下行的电子邮件,该购买是在wordpress mail($to, $subject, $message, $headers);中的woocomerce购买结束时触发的,该电子邮件可以成功触发,但是我希望该电子邮件具有在浏览器中打开的链接,因此可以将HTML格式化为特定的CSS打印设计。有没有一种方法可以自动生成一个HTML文件,我可以为使用php和wordpress发送的每封电子邮件托管一个HTML文件,然后我将分别为这些发送的电子邮件分别添加到这些html文件的链接。我不知道其他解决方案,但也愿意接受其他解决方案。

这是我现在在php文件中构建电子邮件的方式。

$to = $email_user;
    $subject_decoded = 'You received a gift card for stuff';
    $subject = '=?UTF-8?B?' . base64_encode( $subject_decoded ) . '?=';
    $subject1 = 'test';
    $message = '<table border="0" cellspacing="0" cellpadding="0" width="100%" style="width: 100%; border-collapse: collapse;"><tbody><tr><td style="padding: 40px 40px 20px; background-color: #f9f9f9;" align="center"><table border="0" cellspacing="0" cellpadding="0" width="600" style="border-collapse: collapse;"><tbody>';
    $message .= '<tr><td align="center" valign="bottom" style="padding: 0 0 20px;">';
    $message .= '<img src="https://dev.website.com/wp-content/uploads/2019/05/RCDH-ComLogo.png" alt="place" width="600" height="87" style="vertical-align: bottom;" />';
    $message .= '</td></tr>';
    $message .= '<tr><td align="center" style="padding: 10px 40px 20px; background-color: #ffffff; color: #676767; font-family: Helvetica, Arial, sans-serif;">';
    $message .= '<h2 style="font-family: Garamond, serif; font-size: 28px; font-weight: 600; color: #444444;">' . (!empty($gift_card_data['recipient_name']) ? $gift_card_data['recipient_name'] : 'Whoa') . ', you&rsquo;ve got ' . $gift_card_data['gift-card-amount'] . ' to spend at place; | Deane&nbsp;House!</h2>';
    $message .= '<p style="color: #676767;">' . (!empty($gift_card_data['sender']) ? $gift_card_data['sender'] : 'Someone') . ' sent you a gift card' . (!empty($gift_card_data['message']) ? ' with the following message:' : '.') . '</p>';
    if( !empty($gift_card_data['message']) ) {
      $message .= '<p style="color: #676767;"><i><br />' . nl2br($gift_card_data['message']) . '<br /><br /></i></p>';
    }
    $message .= '<img src=" ' . $gift_card_image . '"/>';
    //$message .= '<img src="https://www.barcodesinc.com/generator/image.php?code=' . $response->result[3] . '&style=68&type=C39&width=300&height=50&xres=1&font=4" alt="" />';
    // barcode generator website: https://www.barcodesinc.com/generator/index.php
    $message .= '<p style="color: 676767; font-size: 1.25em;"><b>Card Number:</b> ' . $response->result[3] . '<br /> <b>PIN:</b> ' . $response_reference[1] . '<br /> <b>Card Amount:</b> ' . $response->result[4] . '<br /> <b>Reference Number:</b> ' . $response_reference[0] . '</p>';
    $message .= '</td></tr>';
    $message .= '<tr><td align="center" style="padding: 20px 0 0;">';
    $message .= '<p style="color: #676767;"><b>We look forward to you dining with us!</b></p>';  
    $message .= '</td></tr>';
    $message .= '</tbody></table></td></tr></tbody></table>';
    $headers = "From: Gift Cards <[email protected]>\r\n";
    $headers .= "Reply-To: noreply@website\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    mail($to, $subject, $message, $headers);

提前感谢。

php wordpress html-email
1个回答
1
投票

这里有个主意:

  • 使端点接受ID,例如html-email/{id}
  • $message的内容并将其存储在数据库中,插入具有两个字段的表中:
    • 非增量自动生成的ID
    • $message内容的文本
  • 获取新创建的条目的ID
  • 生成指向您页面的链接html-email/{id}
  • 附加到$message
  • 发送电子邮件

一旦从电子邮件本身单击链接,您就可以加载存储的消息内容并根据需要显示。

© www.soinside.com 2019 - 2024. All rights reserved.