2013-10-04 47 views
2

我試圖發送一個確認電子郵件使用phpmailer,但堅持一個問題。 郵件的內容位於一個名爲page_mail.php的頁面中,我使用php郵件發送此內容,但是當我收到電子郵件時,它將返回「1」。php變量使用phpmailer

你們能幫助我嗎?

這裏是我的代碼

$req = mysql_query("SELECT * FROM users WHERE email='[email protected]'") or die(mysql_error()); 
$info = mysql_fetch_array($req); 

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

$mail = new PHPMailer(); 
$mail->IsSendmail(); 
$mail->AddAddress("[email protected]"); 
$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'); 

回答

1

您應該使用的,而不是$body = include('page_mail.php');一些輸出緩衝技術。從official documentation見例如:

$string = get_include_contents('somefile.php'); 

get_include_contents()定義如下:

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

編輯:

如果你打算使用page_mail.php一些全局變量,在你的主要定義PHP文件,那麼我推薦使用這個解決方案:https://stackoverflow.com/a/10144260/925196