PHP script doesn't work in a specific order
I have a simple HTML that displays an image using the PHP script link shown below. After the HTML page loads, I want to display the image in the browser and send an email to a specific email.
The below PHP script works fine. However, when I move the "Show Image in Client Browser" code from top to bottom script, the program only sends an email message and does not return the image to the HTML page. Can someone tell me why this is happening and how I can fix it.
HTML code of the page:
<body>
<img src="http://www.inoxel.com/test/image&email.php >
</body>
image & email.php PHP script file that works:
<?php
// Show image in browser client.
$logo = "http://www.Inoxel.com/test/happy_face2.gif"; // Set image Full Path
readfile($logo);
// Send a test email.
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "mblasberg@inoxel.com";
$to = "menb@pacbell.net";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>
image & email.php PHP script file that doesn't work:
<?php
// Send a test email.
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "mblasberg@inoxel.com";
$to = "menb@pacbell.net";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
// Show image in browser client.
$logo = "http://www.Inoxel.com/test/happy_face2.gif"; // Set image Full Path
readfile($logo);
?>
source to share
Readfile () function Reads a file and writes it to the output buffer
. When you call this function, it will mimic the behavior of the web server when delivering a file from the file system. So echoing this file is at least completely useless, because best of all it will damage the file (since it sends byte data and your string, which is not part of the file).
You can send mail in the same script, which is not a problem at all. But if you want to know if an email was sent, either write something in your log files, or do it with a separate (xhr) request.
source to share