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='[email protected]'") or die(mysql_error());
$info = mysql_fetch_array($req);

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

$mail = new PHPMailer();
$mail->IsSendmail();
$mail->AddAddress("[email protected]");
$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');

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.