包括外部php文件到php邮件正文

时间:2016-05-30 12:26:15

标签: email php html

     if($_POST['mail'])
    {
 $to_name = $rows['username'];
$to = $rows['email'];
$subject = "Invoice";



   $from_name = "abc.com";
 $from = "noreply.com@abc.com";

 // phpMailer
 require_once('phpmailer/PHPMailerAutoload.php');
 $mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "smtp.gmail.com"; //enable php socks to make SSL it working
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';    
$mail->Username = "email@gmail.com";
$mail->Password = "password";

$mail->FromName = $from_name;
$mail->From = $from;
$mail->AddAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body = include'invoice.php';  
$mail->IsHTML(true);    
$result = $mail->Send();
}
?>

而是向我显示php页面,它在邮件中没有显示任何内容!

1 个答案:

答案 0 :(得分:3)

这是执行此操作的正确方法:

ob_start();
include('invoice.php');
$mail->Body = ob_get_contents();
ob_end_clean();