AgeDeO
AgeDeO

Reputation: 3147

PHP mailer (message body empty)

I am new to PHPMailer and I want to send an HTML mail with this class. But I Get the message that the body is empty.

This is my code:

<?php        

$bericht .= 'my html and php code that format the mail';

require_once('class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = preg_replace('/[\]/','',$bericht);

$mail->SetFrom('email@adres', 'Name');

$address = "email@adres";
$mail->AddAddress($address, "");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);


if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

What am I doing wrong?

Upvotes: 0

Views: 4575

Answers (3)

Seiji Manoan Seo
Seiji Manoan Seo

Reputation: 19

I misunderstand why you need to do this INCREMENT with the variable if it has no need.

$bericht .= ...;

And yes, where's the string value within quotes right in there?

Upvotes: 0

Lappies
Lappies

Reputation: 923

i think there is an error in you code

$bericht .= (my html and php code that format the mail);

should be

$bericht = 'my html and php code that format the mail';

and then instead of this

$body             = $bericht;
$body             = preg_replace('/[\]/','',$body);

its easier to do this

$body             = preg_replace('/\[\]/','',$bericht);

Upvotes: 0

Ale
Ale

Reputation: 1839

I think there is a problem with your preg_replace(). If I try to run this on my server I get this warning:

Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 3

Did you try the code without the preg_replace(), i.e., just by passing $bericht to MsgHTML()?

Upvotes: 1

Related Questions