如何使用php会话变量发送邮件

用户名

我想发送具有以下会话变量的邮件,但我获取的HTML内容没有变量。有什么建议?

................................................... ...................................................

PHP代码:

$servicenumber = $_SESSION['number'];
$amount = $_SESSION['amount'];



require_once('libraries/PHPMailer.php');

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com';                 // Specify main and backup server
$mail->Port = 587;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'username';                // SMTP username
$mail->Password = 'key';                  // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also    accepted

$mail->From = '[email protected]';
$mail->FromName = 'test';
$mail->AddAddress('[email protected]', 'Pranjal');  // Add a recipient
$mail->AddAddress('[email protected]');               // Name is optional

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = '
                  <table class="six columns" style="border-spacing: 0;border-collapse:    collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 280px;">
                    <tr style="padding: 0;vertical-align: top;text-align: left;">
                      <td class="panel" style="word-break: break-word;-webkit-hyphens:     auto;-moz-hyphens: auto;hyphens: auto;padding: 10px !important;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;background: #f2f2f2;border: 1px solid #d9d9d9;border-collapse: collapse !important;">
                        <h6 style="color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;padding: 0;margin: 0;text-align: left;line-height: 1.3;word-break: normal;font-size: 20px;">Transaction receipt</h6>
                        <p style="margin: 0;margin-bottom: 10px;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 14px;">Details</p>

                        <table style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;">
                          <tr style="padding: 0;vertical-align: top;text-align: left;">
                            <td style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0px 0px 10px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;">
                              Service Number: <a style="text-decoration: none;">&nbsp;&nbsp;&nbsp;&nbsp;</a>  <? echo $service;?>
                            </td>
                          </tr>
                        </table>
                        <hr style="color: #d9d9d9;background-color: #d9d9d9;height: 1px;border: none;">
                        <table style="border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;">
                          <tr style="padding: 0;vertical-align: top;text-align: left;">
                            <td style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0px 0px 10px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;">
                              Amount Paid:<a style="text-decoration: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> <? echo $amount;?>
                            </td>
                          </tr>

                        </table>
                        <hr style="color: #d9d9d9;background-color: #d9d9d9;height: 1px;border: none;">

                                                  </td>
                      <td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0 !important;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;visibility: hidden;width: 0px;border-collapse: collapse !important;"></td>
                    </tr>
                  </table>

                  <br>

                      </td>
                      <td class="expander" style="word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0 !important;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Arial&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;visibility: hidden;width: 0px;border-collapse: collapse !important;"></td>
                    </tr>
                  </table>

                </td>
              </tr>
            </table>


';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
杰蒙德·达尔(Gjermund Dahl)

切记session_start()在任何输出之前运行并且您的邮件内容字符串有错误。您不能使用<? echo $amount;?>将变量包含在字符串中。使用'.$amount.'代替。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章