Message body empty when using phpmailer msgHTML

0

What friends have been watching for a while because he does not send the mail to the recipient, I have the fragment in the action of a form, but not fulfilling the condition I jump to the error "Message body empty", see if can anybody help me. Thanks

<?php
function sendmail($setFromEmail,$setFromName,$addReplyToEmail,$addReplyToName,$addAddressEmail,$addAddressName,$subject,$template){
require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->isSendmail();

$mail->setFrom($setFromEmail, $setFromName);

$mail->addReplyTo($addReplyToEmail, $addReplyToName);

$mail->addAddress($addAddressEmail, $addAddressName);

$mail->Subject = $subject;

$mail->msgHTML(file_get_contents($template));


if (!$mail->send()) {
    echo "Error al enviar mensaje: " . $mail->ErrorInfo;
} else {
    echo "Mensaje enviado!";
}}sendmail('[email protected]','quien envia','[email protected]','a quien responde','[email protected]','quien recibe','Prueba piloto','confirmation.html');?>
    
asked by system_web 17.05.2017 в 20:55
source

1 answer

0

If I'm not wrong, by not having defined $mail->IsHTML(true); by default it marks it in false and if so, the message of your mail should go in $mail->Body(); so you can add to your settings

$mail->IsHTML(true);

EDITING

I have a PHPMailer code like this:

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "user";
$mail->Password = "pass";
$mail->setFrom('[email protected]', 'Contacto');
$mail->addAddress($_POST['email'], 'Contacto');
$mail->Subject = 'Contacto';
$message = file_get_contents('formato_mail.html');
$message = str_replace('%nombre%', $_POST['nombre'], $message);
$mail->msgHTML($message);
$mail->AltBody = 'Contacto';
$mail->IsHTML(true);  
if (!$mail->send()) {
    $result['status'] = 0;
    $result['mensaje'] = 'Ha ocurrido un error. Asegurate de que los datos que ingresaste sean correctos.';
} else {
    $result['status'] = 1;
    $result['mensaje'] = 'Gracias '.$_POST['nombre'].' por contactarte con nosotros. Resolveremos tus dudas a la brevedad.';
}
    
answered by 17.05.2017 / 21:02
source