简体   繁体   中英

PHP output buffering not working

I have a php file that I am trying to send the output in a email using the php mail function (PHPMailer is not an option as the server I am working restricts their SMTP server). The code for the mail function is

$to = "xxx@example.com";
$subject = "Outdoor Grill Service Request";
ob_start();
require 'grill-form.php';
$body = ob_get_clean();
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers = "From: xxx@example.com\n";
mail($to,$subject,$body,$headers);
echo "Mail sent to $to";

grill-form.php is a php file that contains a html file that has tables that are populated with php variable from a form. This worked perfectly using PHPMailer but once I migrated over to standard php mail is got "screwy".

The issue I am running into is when the email sends I am getting raw HTML code and not the output of the grill-form.php (a styled table with values). I have little knowledge with the php mail function so I might be missing something stupid.

Was wondering what I am doing wrong. Thank you in advance for you help you people are the best.

Assuming that's your actual code, you're overwriting the $headers variable with the third declaration, not appending to what you have. The Content-type header is never making it in.

PHPMailer does support SMTP, by the way--what exactly do you mean by "restricts their SMTP server"? (Here's an example: http://phpmailer.worxware.com/index.php?pg=examplebsmtp )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM