PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 7, 2022

[FIXED] How to do file_get_contents() from directory other than __DIR__?

 July 07, 2022     php, phpmailer     No comments   

Issue

I'm sending an email using PHPMailer and this works fine:

$mail->Subject = "My Email Subject";
$mail->msgHTML(file_get_contents('emailcontent.html'), __DIR__);
$mail->send();

The file 'emailcontent.html' is in the current directory and it works.

Now I want to move the 'emailcontent.html' file into subdirectory 'emails/emailcontent.html'.

I tried this ...

$mail->msgHTML(file_get_contents('emailcontent.html'), __DIR__.'/emails/');

... and this ...

$mail->msgHTML(file_get_contents('/emails/emailcontent.html'), __DIR__);

... but neither worked.

What am I doing wrong?


Solution

Thanks to @RiggsFolly for straightening me out ... the problem was an errant /.

This works:

$mail->msgHTML(file_get_contents('emails/emailcontent.html'), __DIR__);


Answered By - AndySummers2020
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing