2

I'm trying to send a confirmation e-mail using phpmailer but stuck with a problem. The content of the mail is in a page called page_mail.php and I'm using php mailer to send this content but when I receive the e-mail it returns "1".

Can one of you help me ?

Here's my code

$req = mysql_query("SELECT * FROM users WHERE email='test@test.com'") or die(mysql_error());
$info = mysql_fetch_array($req);

$body = include('page_mail.php');
    echo $body;

$mail = new PHPMailer();
$mail->IsSendmail();
$mail->AddAddress("test@test.com");
$mail->Subject = "MAIL TEST";
$mail->MsgHTML($body);
$mail->AltBody = "Ce message est au format HTML, votre messagerie n'accepte pas ce format.";
$mail->Send();

ini_get('sendmail_path');
Grzegorz Adam Kowalski
  • 5,243
  • 3
  • 29
  • 40
jmouk
  • 21
  • 5

1 Answers1

1

You should use some output buffering techniques instead of $body = include('page_mail.php');. See example from official documentation:

$string = get_include_contents('somefile.php');

Where get_include_contents() is defined as follows:

function get_include_contents($filename) {
    if (is_file($filename)) {
        ob_start();
        include $filename;
        return ob_get_clean();
    }
    return false;
}

EDIT:

If you intend to use some global variables in page_mail.php which are defined in your main PHP file, then I recommend using this solution: https://stackoverflow.com/a/10144260/925196.

Community
  • 1
  • 1
Grzegorz Adam Kowalski
  • 5,243
  • 3
  • 29
  • 40