Image I insert into email body using TinyMCE does not appear in email
I'm trying to send an email with one or more images that I uploaded using tinymce textarea, where I write the email to be sent, I write what I want and upload the image, it appears there but does not send in the email, when I look at the email sent only appears what was typed and not the image
Function code sending email:
function send_mail($con){
if(isset($_POST['env']) && $_POST['env'] == "email"){
$destinos= explode(',',$_POST['destinos']);
$mail = new PHPMailer();
$mail->Host = 'smtp.gmail.com';
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = '[email protected]';
$mail->Password = 'senha';
$mail->Port = 465;
#$mail->Port = 587;
for($i=0; $i<count($destinos); $i++){
$mail->setFrom('[email protected]', 'Stephanto');
$mail->addAddress($destinos[$i]);
$mail->addReplyTo('[email protected]');
$mail->isHTML(true);
$mail->Subject = $_POST['assunto'];
$mail->Body = $_POST['mensagem'];
}
if(!$mail->send()){
echo "<div class='alert alert-danger'>Erro ao enviar o E-mail! </div><br>";
echo "Erro: ".$mail->ErrorInfo;
}
}
Email sending page Code:
<script src="https://cloud.tinymce.com/5/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea',
plugins: 'image code',
toolbar: 'undo redo | image code',
images_upload_url: '../lib/upload.php',
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', '../lib/upload.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != 'string') {
failure('Invalid JSON: ' + xhr.responseText);
return;
}
success(json.location);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
},
});
</script>
<form method="POST" enctype="multipart/form-data">
<label>Destinatários</label>
<input type="text" name="destinos" class="form-control" value="<?php get_emails($con); ?>"><br>
<label>Assunto</label>
<input type="text" name="assunto" class="form-control"><br>
<label>Mensagem</label>
<textarea name="mensagem" rows="20"></textarea><br>
<p align="right"><input type="submit" name="" value="Enviar e-mail" class="btn btn-outline-success btn-lg btn-block"></p>
<input type="hidden" name="env" value="email">
</form>
<p align="left"><button class="btn btn-outline-primary btn-lg btn-block" onclick="window.location.href='index.php?pagina=inicio'">Cadastrar e-mails</button></p>
</div>
<?php send_mail($con); ?>
Upload code.php
<?php
$accepted_origins = array("http://localhost", "http://107.161.82.130", "http://codexworld.com");
$imageFolder = "../imagens/";
reset($_FILES);
$temp = current($_FILES);
if(is_uploaded_file($temp['tmp_name'])){
if(isset($_SERVER['HTTP_ORIGIN'])){
if(in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)){
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
}else{
header("HTTP/1.1 403 Origin Denied");
return;
}
}
if(preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])){
header("HTTP/1.1 400 Invalid file name.");
return;
}
if(!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))){
header("HTTP/1.1 400 Invalid extension.");
return;
}
$filetowrite = $imageFolder . $temp['name'];
move_uploaded_file($temp['tmp_name'], $filetowrite);
echo json_encode(array('location' => $filetowrite));
} else {
header("HTTP/1.1 500 Server Error");
}
?>
0