Avatar of Chimeraza
Chimeraza
Flag for South Africa asked on

With PHPMailer (Class) - How do I use a separate php file as my (embedded) html email message

Using PHPMailer, I want to use a seperate php file as my email (html) message...

so that this...
$mail->Body = $html;   // <-- This line

would look something like this..
$mail->Body = email.php (or something along those lines).

Thanks in advance!
ProgrammingPHP

Avatar of undefined
Last Comment
Chimeraza

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Loganathan Natarajan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Loganathan Natarajan

sample script,


<?php
 
include_once('../class.phpmailer.php');
 
$mail    = new PHPMailer();
 
$body    = $mail->getFile('contents.html');
 
$body    = eregi_replace("[\]",'',$body);
$subject = eregi_replace("[\]",'',$subject);
 
$mail->From     = "name@yourdomain.com";
$mail->FromName = "First Last";
 
$mail->Subject = "PHPMailer Test Subject";
 
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
 
$mail->MsgHTML($body);
 
$mail->AddAddress("whoto@otherdomain.com", "John Doe");
 
if(!$mail->Send()) {
  echo 'Failed to send mail';
} else {
  echo 'Mail sent';
}
 
?>

Open in new window

Chimeraza

ASKER
Thanks for the prompt response

I tried that but am getting this error..

Fatal error: Call to a member function getFile() on a non-object in /home/content/t/e/a/mydomain/html/db/emailer_cus.php on line 36

Please help.
Loganathan Natarajan

Don't you have the getFile() function on the phpmailer.class

try to use the attached file..

class.phpmailer.php.txt
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Chimeraza

ASKER
my current file does have the getFile() function.. ?
Loganathan Natarajan

have you included the right path on the top of the page?

include_once('../class.phpmailer.php');

Open in new window

Chimeraza

ASKER
yea I have, any ideas?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Loganathan Natarajan

can u post the complete code?
Chimeraza

ASKER
Its working now for some reason! Thanks