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

如何使用php会话变量发送邮件,php,Php,我想用下面的会话变量发送邮件,但我得到的html内容没有变量。有什么建议吗 徖 PHP代码: $servicenumber = $_SESSION['number']; $amount = $_SESSION['amount']; require_once('libraries/PHPMailer.php'); $mail = new PHPMailer; $mail->IsSMTP(); // Set m

我想用下面的会话变量发送邮件,但我得到的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 = 'someone@gmail.com';
$mail->FromName = 'test';
$mail->AddAddress('some@gmail.com', 'Pranjal');  // Add a recipient
$mail->AddAddress('ellen@example.com');               // 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;
}
$servicenumber=$\u会话['number'];
$amount=$\会话['amount'];
一次需要_('libraries/PHPMailer.php');
$mail=新的PHPMailer;
$mail->IsSMTP();//将邮件程序设置为使用SMTP
$mail->Host='smtp.mandrillapp.com';//指定主服务器和备份服务器
$mail->Port=587;//设置SMTP端口
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username='Username';//SMTP用户名
$mail->Password='key';//SMTP密码
$mail->SMTPSecure='tls';//启用加密,也接受“ssl”
$mail->Fromsomeone@gmail.com';
$mail->FromName='test';
$mail->AddAddress('some@gmail.com“,”Pranjal“;//添加收件人
$mail->AddAddress('ellen@example.com');               // 名称是可选的
$mail->IsHTML(正确);//将电子邮件格式设置为HTML
$mail->Subject='主题在这里';
$mail->Body=
交易凭证
详细信息

服务号码:
支付金额:

'; $mail->AltBody='这是非HTML邮件客户端的纯文本正文'; 如果(!$mail->Send()){ echo“无法发送消息”; 回显“邮件错误:”。$mail->ErrorInfo; 出口 }
记得在任何输出之前运行
会话\u start()
。 您的邮件内容字符串有错误。您不能使用
将变量包含到字符串中。改用“
”.$amount.