I'm sending an email using php's mail() function. My code is as following:
$to = email@email.com;
$subject = "Subject of email";
ob_start();
echo include('emailcontent.php');
$message = ob_get_contents();
ob_end_clean();
$headers =
'From: Email ' . "\r\n" .
'Reply-To: Email ' . "\r\n" .
"Content-type:text/html;charset=UTF-8" . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
For some reason the string "1" is added at the end of the message. This happens in the include('emailcontent.php'), because if I add another string to the message after the include the "1" is added before that addition.
In the emailcontent.php is no 1 or whatsoever.
Answer
echo include('emailcontent.php');
Remove the echo. That echo puts 1 in there
You might ask why does echo put 1 in there when its not added anywhere? Because when your file is successfully included the return value of that include is TRUE and when you send that to echo it prints 1. Try
echo 2==2; //1
No comments:
Post a Comment