使用phpmailer的php变量

使用phpmailer的php变量,php,include,phpmailer,file-get-contents,Php,Include,Phpmailer,File Get Contents,我正在尝试使用phpmailer发送确认电子邮件,但遇到问题。 邮件的内容在一个名为page_mail.php的页面中,我使用php mailer发送此内容,但当我收到电子邮件时,它返回“1” 你们中有人能帮我吗 这是我的密码 $req = mysql_query("SELECT * FROM users WHERE email='test@test.com'") or die(mysql_error()); $info = mysql_fetch_array($req); $body = i

我正在尝试使用phpmailer发送确认电子邮件,但遇到问题。 邮件的内容在一个名为page_mail.php的页面中,我使用php mailer发送此内容,但当我收到电子邮件时,它返回“1”

你们中有人能帮我吗

这是我的密码

$req = mysql_query("SELECT * FROM users WHERE email='test@test.com'") or die(mysql_error());
$info = mysql_fetch_array($req);

$body = include('page_mail.php');
    echo $body;

$mail = new PHPMailer();
$mail->IsSendmail();
$mail->AddAddress("test@test.com");
$mail->Subject = "MAIL TEST";
$mail->MsgHTML($body);
$mail->AltBody = "Ce message est au format HTML, votre messagerie n'accepte pas ce format.";
$mail->Send();

ini_get('sendmail_path');

您应该使用一些输出缓冲技术,而不是
$body=include('page_mail.php')。参见以下示例:

其中
get\u include\u contents()
的定义如下:

function get_include_contents($filename) {
    if (is_file($filename)) {
        ob_start();
        include $filename;
        return ob_get_clean();
    }
    return false;
}
编辑:

如果您打算在主php文件中定义的
page_mail.php
中使用一些全局变量,那么我建议使用以下解决方案:

function get_include_contents($filename) {
    if (is_file($filename)) {
        ob_start();
        include $filename;
        return ob_get_clean();
    }
    return false;
}