Hi, I wanna know how to solve this problem Send a image as a email, that is stored in mysql database.
my code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Envio emailo</title>
</head>
<body>
<br><br>--------------------------------------- <br><br>
<form method="post" action="">
data: <input type="date" name=Date > <br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"]=="POST"){
$sel=$_POST["Date"];
require_once 'dbConfig.php';
// Check connection
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM TableWHERE data='".$sel."'";
$result = mysqli_query($mysqli, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$msg ='<html><body>';
$msg .= '<p style="color:#080;font-size:18px;">';
$msg .= "text1: " .$row["c1"]. "<br>";
$msg .= "text2: " .$row["c2"]. "<br>";
";
$msg .= "imagem: <img src='data:image/jpg;charset=utf8;base64,'" .base64_encode($row['image']);
$msg .= '</p></body></html>';
// echo($msg);
$msg = wordwrap($msg,70);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8'. "\r\n";
$headers .= 'From: pomme <[email protected]>' . "\r\n";
$header .= "Content-Transfer-Encoding: base64";
$headers .= '\r\nContent-Type: multipart/mixed;';
if(mail("[email protected]","Encomenda",$msg,$headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
}
} else {
}
mysqli_close($mysqli);
}
?>
</body>
</html>