Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Enhancing a Simple PHP Application Cleaning URLs with Subfolders Using Absolute Server Paths

Mailtodisk Error Message

I am on the Absolute Paths section of the Enhancing A Simple PHP App course. I am having problems trying to find my document root folder. I have entered this code at the top of my index.php file inside the Receipt directory.

var_dump($_SERVER["DOCUMENT_ROOT"]);
die();

I am entering information into the contact form and submitting it. Then, I receive an error message that says "mailtodisk.exe" and that basically it's trying to write to my disk drive. I'm sure it's something related to phpmailer, but I haven't figured it out yet.

Thanks as always!

PS I should have mentioned that I am using a XAMPP server on Windows 8.

Andrew Shook
Andrew Shook
31,709 Points

Are you using Windows? If so, what version?

Win 8

Andrew Shook
Andrew Shook
31,709 Points

are you using Xamp or Wamp?

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

I assume you're running Mercury Mail with your xampp installation. Either turn it off if you don't use it or attempt the following.

You may have to edit a line or two in your php.ini file. This file is probably located in C:\xampp\php\php.ini - or where your xampp install directory then the php directory.

Once php.ini is open in an editor search for the following line (mine was near line #1140):

; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

Remove the ; from start of ;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Add a ; to the start of sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

Then save the file (you may need administrator rights for this) and restart Apache.

Let's hope for the best and see if that works. :)

Thanks, Sean! I was just reading up on that. Your directions make it a lot clearer, though. I'll try it shortly and see what happens.

Unfortunately, I'm still getting the mailtodisk error. I uncommented the sendmail line as you noted above. I noticed the sendmail path after it that points to mailtodisk.exe was uncommented, as well. So I commented out that one by placing a semi-colon before it. Still no go. I also deleted the -t" after the first sendmail line, but that didn't do anything either. I'm wondering if I need to configure something in the sendmail folder?

Sean T. Unwin
Sean T. Unwin
28,690 Points

Don't delete the -t part.

Are you running Mercury Mail? If so have you tried turning it off?

I haven't tried turning off Mercury mail. I overlooked that. I'm looking how to do that now. Thanks for the tip about not deleting the -t.

Since I never started Mercury in the xampp control window, I'm guessing that I never started it. Now I'm wondering if I should install it, since all I need is a simple mail program to test in from xampp. I'll give that a try and see what happens.

Sean T. Unwin
Sean T. Unwin
28,690 Points

I could not replicate the error you are receiving after some attempts at trying. Sorry.

Could you do a test? Create a new php file in another directory, apart from the Shirts4Mike directory, and put the code from your op in that file and let me know if you get a different response when you view the page in your browser.

If you are going to enable Mercury Mail and want to use it with your email client:

  • follow my directions above -- uncomment the line with the -t and comment out the other one
  • open xampp/xampp-control.ini and add Mercury=1 to the [EnableServices] section (if you want to run it as a service)
  • follow this tutorial - http://www.c-sharpcorner.com/UploadFile/c8aa13/send-mail-on-local-host-via-mercury-with-xampp/ - to set up a test email account. If you use Thunderbird instead of Outlook, as in the tutorial, just set up a new account as usual using localhost or localhost.com as the smtp server -- it's all in the tutorial, but if you have trouble post here.

Sorry for taking so long to get back. I got pulled away for a day. Thanks a lot, btw, for the great directions above. Really. But before I try and initiate it today, I was wondering whether or not I should run Mercury as a service. I am running on a Windows machine. Maybe I don't fully get all of the benefits of running a service, but it seems to me that it's really only that beneficial if you're using more than one mail client. I'm really just wanting to use Mercury when I'm on localhost, and then I'll use the phpmailer default when I'm online. What's your opinion on this?

Sean T. Unwin
Sean T. Unwin
28,690 Points

It won't show up in your task bar if you run it as a service. You can control it from the xampp-control in the system tray, if you installed xampp as a service. Less clutter, imo.

The above is usually true in most cases although that's more to do with installing something as a service, I think, so I'm not sure if it's relevant if you didn't install Mercury as a service when you installed xampp.

Good question; too bad I can't answer it better, but If I recall correctly I had to set the above marker in the xampp-control.ini or Mercury would stop after I started it. So I guess that's the main reason; ymmv however.

Hi, Sean,

Sorry it's taken me so long to get back. Work sort of took over and I've been in development hell for a good two weeks.

I started following the directions in the link you posted. But now I'm debating using Pegasus over Thunderbird. i tried to set up Thunderbird, but I didn't realize there was a charge for creating an email. Anyway, I hope to finish this up this week, or weekend at the latest. Thanks for helping me out. I appreciate it. Talk to you soon.

Hey, Sean,

Don't know if you're still out there or not, but I followed your directions above and I can't seem to get past setting up my mail account in Thunderbird. Each time I enter my server settings and hit 'done', I get an error saying either my username or password is incorrect. I'm using a simple three digit password and 'benjgold' for the username. Here are the settings I'm using.

Incoming - POP3 Host Server - 127.0.0.1 Port - 995 SSL - SSL/TLS Authentication - Normal Password

Outgoing - SMTP Host Server - 127.0.0.1 Port - 465 SSL - SSL/TLS Authentication - Normal Password

I've also tried setting the server name to 'localhost', and 'benjgold@localhost'.

Appreciate any suggestions. Thanks!

Sean T. Unwin
Sean T. Unwin
28,690 Points

G'day Ben.

Make sure that what you have set for your Local Domains in Step 5 of the above tutorial that I posted is the same that you are using in Thunderbird.

Also, double check your port settings from Steps 6-9 and make sure they are set to the same in Thunderbird.

I went back through those steps and I saw that I was using the incorrect ports in Thunderbird. I changed the ports and clicked 'done'. This time it went on to a completion window, warning me about not using encryption. I clicked that I understood the risks and hit okay. But then it went back to the settings window, saying that the password was incorrect. I made one small change. I switched my ingoing/outgoing username from my email address to just my regular username. I hit done and the settings box disappeared. Now I see my email address being displayed in the sidebar, as well as my inbox and outbox. I dare say this might have worked. I'm too scared to try it right now. I'm going to take a break and then test it later. But I definitely think I'm getting somewhere. Thanks, Sean! I'll report back later in the day.

At this point, it's been so long since I started trying to set all of this up, that I'm having a hard time retracing back to where I was initially. I'm afraid this might take me more than a day to sort out. Right now, when I run the "var_dump" code that I originally posted about, nothing happens. So, like I said, I might have to retrace my steps and go back a couple of lessons to see if I can figure out why that is. Two steps forward and one step back, I guess. I'll post here when I figure something out. Thanks.

Okay. I've gone back through the lessons and I seem to be caught up.

I was finally able to find the path to my root folder. Turns out I wasn't including the correct url to the receipt page when I ran the var dump. So that's done

My only issue now is trying to get my mail working. As I said before, the Thunderbird account is working. I set up Mercury according to your instructions and those of the tutorial. But when I try to just go ahead and send an email, with or without Mercury running, I get "There was a problem sending the email: Could not instantiate mail function."

So that's currently where I'm at. Once the mail is finally working, I think I can die a happy man.

Sean,

Thanks for all of your help. I think I'm going to call it quits on using Mercury, and try using SMTP with phpmailer. Thanks again for taking the time. Appreciate it.