Send mail with phpmailer

0

I have the following code in phpmailer but when sending the mail, it sends me the following error

"Call to undefined method PHPMailer::body()" 

the version of phpmailer that I use is 5.2.4

<?php

require_once('phpmailer/class.phpmailer.php');
require_once('phpmailer/class.smtp.php');


$mail = new PHPMailer(); 

$mail->CharSet = 'UTF-8';

$mail->IsSMTP();

$mail->SMTPAuth = true;

$mail->SMTPSecure = 'tls';


$mail->Host = 'smtp.gmail.com';

$mail->Port = 587;

$mail->Username   = "micorreo";

$mail->Password   = "micorreo";

$email_to = "correo";
$email_subject = $_POST['asunto'];
$email_copy = $_POST['email'];
$body = $_POST['comments'];
$name = $_POST['nombre'];

$mail->SetFrom($email_copy, $name);


$mail->AddReplyTo($email_copy,$name);

$mail->AddAddress($email_to, 'nombre');  

$mail->Subject = $email_subject;

$mail->IsHTML(false);
$mail->body($body);


if(!$mail­>Send()) {
echo "Error al enviar el mensaje: " . $mail­>ErrorInfo;
} else {
echo "Mensaje enviado!!";
}
?>
    
asked by Rafa FE 17.04.2017 в 17:39
source

2 answers

2

You must define the body of the message using Body with initial capital B. For example:

 $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";

(Example taken from link )

Another option is to use the MsgHTML() method, which allows you to define the message using HTML format. For example:

$mail->MsgHTML("<p>Enviando mensaje <b>con formato HTML</b>.</p>");
    
answered by 17.04.2017 / 18:11
source
0

You have also tried to modify IsHTML(false); , and put it in true .

Example:

//Envio de correo electronico mediante HTML o texto plano.
$mail->isHTML(true);

$mail->Subject = $email_subject;
$mail->Body = "<i>Cuerpo mediante HTML.</i>";
$mail->AltBody = "Cuerpo mediante texto plano.";
    
answered by 17.04.2017 в 18:33