Mail() problem

I have just moved one of my sites onto DH and I am having a problem with the PHP mail() function, It won’t work!. I stripped it down to its core but still nothing. It works on the other server but not here. Any suggestions.

/* additional headers */
$headers .= “Return-Path:” . $return . “\r\n”;
$headers .= “From:”. $from ."\r\n";
mail($recipient, $subject, $body,$headers);

http:// - Auction off your web site real estate.

Has anybody else had a problem sending mail via PHP? If it works for you can you tell me what you did?

http:// - Auction off your web site real estate.

I thought someone knowledgable about this would answer. But…seems they haven’t. I believe that the $ function is the problem. Read the knowledge base on the subject and the DH announcements concerning their prohibitions for security reasons. I think the solution you need to to rename your script to something like .pcgi or some such. My main script man isn’t in today, so I can’t ask him the end tag, but it is in the knowledge base.

In answer to whether we send email via .PHP, we send email USING several .PHP programs, but the function uses sendmail. If you want to use the POP mail, you have to name the mail server (yours) which is different than your site server.

That’s my best answer, but it is probably all wet according to the scripting and DH gurus around here.

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

Thanks Zentao,

I done a search on the knowledge base for ‘sendmail’ but could only find info about filtering. I also searched for ‘php email’, mail(), email etc… but to no avail.

Does anybody know where I can get more info about using ‘sendmail’ on DH server?

http:// - Auction off your web site real estate.

Where is my master’s degree coder when I need him. Taking a day off, that’s where. Argh!

sendmail requires the -t switch

That much I know.

About PHP: It isn’t the $, it’s these:

From the KBase:

If you are having trouble with PHP commands like backticks (``), system(), exec(), passthru(), and others that spawn external commands, or are having trouble with errors like:

open_basedir Restrictions in effect, file is in wrong directory

Then you’ve written a script that doesn’t quite conform to our security standards.

We implement strict security for PHP scripts run by Apache, because otherwise, none of our users would be able to sufficiently secure sensitive information (like Database passwords)!

Because PHP normally runs as part of Apache, it runs as Apache’s user and group. This differs from CGI scripts, which, because they run as a separate process outside Apache, run as the owner’s user and group.

To protect your PHP scripts, we’ve disallowed all PHP functions that would let one user possibly open another user’s script (and see sensitive stuff like passwords). Our restrictions work in two parts:


open_basedir restrictions prevent any of PHP’s file opening commands from working on any files outside of /home/youruser. Files BELOW that directory WILL WORK:

/home/youruser/phpstuff/some/more/dirs/ IS OK! PHP CAN OPEN IT!

If you need to open files in another user’s home directory (assuming both are under you account, of course!) contact TS and they will happily make an exception for you.

NOTE: There have been some strange bugs that appeared with respect to open_basedir. Sometimes files that ARE in your home directory trigger an open_basedir error when they really shouln’t. Notify support when this happens.


We have disabled the backticks operator (``), system(), exec(), passthru(), and dl() because all of these functions could be used to run naughty external processes as Apache’s user.

If you need to use these functions, we have provided a second PHP system, PHP-CGI, which runs all your PHP scripts as if they were CGI’s, so they run as your user and group. There are no restrictions on these scripts (not even open_basedir restrictions).

TO HAVE A SCRIPT RUN AS PHP-CGI, simply rename the script so that it ends in .pcgi instead of .php.

If you have lots of files you don’t want to rename, and are sure that all files named .php should be run as PHP-CGI, you can make an .htaccess file containing this:

AddType php-cgi .php

Contact support if you have any questions!


FROM DH 9-10-2001
The first security change will be that your PHP scripts will only be allowed to open other files that reside within your home directory. You WILL be able to share code between domains as long as both are under the same user.

However, if you need to share code between domains that are not in the same user’s home directory we will be able to do a custom setup for you to work around the new restriction. Contact support ( and let them know that you’re a special case.

This restriction will be enforced sometime midday (Pacific time) on Monday September 24th.

The second restriction will prevent any PHP script from executing any external commands. The backticks (``) operator will be disabled, as will the system(), passthru(), exec(), and all other related functions that execute external commands. We’re really sorry to have to do this, but it is in everyone’s best interests.

HOWEVER, fear not! We are working around this problem as well. If you desperately need to execute functions from PHP, you will be able to run your scripts as normal CGIs which will then run as your user and group. We haven’t finished the implementation of this feature but it will be ready soon. We absolutely WILL NOT turn off execution without people convert their scripts. It should be painless and pretty much just involve changing the file extension to something like .pcgi.

The execution of all external commands from within PHP scripts will be disallowed as of Monday, October 8, 2001.

Hope that helps. If not, ask again. I notice that the script you have up there is for a header call. Am I right? What are you trying to do?

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

Yes, you need to send headers when sending email. What I am trying to do is send an email to a client after they purchase something. The email will display the items bought etc…


http:// - Auction off your web site real estate.

Okay. my cgi programs do that, no problem. What is you .php not doing? And if it worked over on another server, my guess would be to change the file tags to .pcgi and see if they work then.

I know that the restrictions do pop up some nasty anomalies and Steve and I get to work through practically every damned script we get asked to install, but the security on this host is excellent, so, despite my bitching about having to deal with it, their restrictions are worth it…did I say that? I should be shot.

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

Coming back to those $. If I remember right, we had to do a complete hack on one .php program to get it the email to work that used a similar scripting. My guess would be to check the scripts documentation and the mailinglist/forum for users encountering similar problems. Or email the guy who wrote the program. Also, I believe…without looking through my shortcuts…can help.

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

speaking of this, has anyone gotten the mail stuff in phpbb to work?

i just created a user on a test forum and didn’t get a confirmation email - so i’m guessing that there is a similar problem with this.

*** note ***

i just got the mail – ok - so i’m impatient.

It works fine in phpBB2 forums on DH. I have two running.


Oh, you’ve got my bug, have you? And no cure for it besides chewing fingernails! :wink:

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

zentao -
Is there any chance that your "my master’s degree coder " is in today. I am out of ideas. No matter what I try I cannot send a simple email.

http:// - Auction off your web site real estate.

No. His wife is trying to have a baby. But I can call him. Chances are he has his laptop with him. What script and, if applicable, what mod?

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

That’s Ok, If his wife is having a baby, I think that is a way more important.

Maybe if you could find that script he uses to send email via PHP and get that to me then I could figure out how he worked around these problems and emulate it.

I was hoping that DH support would scour the forums at intermittent times and answer some of these problems. I realize that DH wants a secure ship but sometimes you can take that too far where it is rendered useless.

Oh well, enough venting.

http:// - Auction off your web site real estate.

I just called him. He says 1) check your permissions. That is the biggest #1 Oops. 2) All 777 MUST be 755 on DH. Must. Won’t work otherwise. 3) He says he needs to know the script. He might know the source builders. 4) What exact error are you getting?

now for my inept contribution. Went over to the devnet forum. on search I came up with this: Check this out. Maybe it will help:

zentao web design, graphic art and design at

zentao7, Gallery of Artists and Speculative Novel Writers Groups

Hi irish -

Various DH people drop into the forums from time to time, but it actually is fairly intermittent, and we don’t have a policy of it (basically it’s mostly Will and I, when we get a moment).

The discussion forums are aimed more toward those problems that aren’t really something our Support Team can handle. Stuff like installation gotchas for an arbitrary script of some kind, or recommendations for web design ideas, etc. Stuff like that, that other DreamHost customers might have a chance to comment on.

If it’s something related to our implementation of something - such as PHP - you can feel free to post a message here, but you should also send one to the Support Team. They can usually give you the Official Word™ on any peculiarities you might find.

That said, sometimes someone like Wil will come along and make us look bad by answering your question first. I’m starting to think that we really should consider paying him for his time. :>

  • Jeff @ DreamHost
  • DH Discussion Forum Admin

[quote]I’m starting to think that we really should consider paying him for his time. :>


Do we have any more t-shirts or sweatshirts (not the ugly orange Dreamservers t-shirts :>)? I think he should definitely get some sort of clothing article (and of course more DreamHost pens than he can ever use)…

I’ll buy him a pint or two next time I’m on that side of the pond too :>

Thanks for the kind words, guys! It’s a pleasure to work with such a great team! It really is…

My Geography is awful, but I’ll be visiting Vancouver in November ~ish… how far are you guys away from Vancouver? That beer could well be on! :slight_smile:


Web Developer

Hi Wil -

Los Angeles is a long, long ways from Vancouver. As in 1,500 miles or so.

Have fun, though. I grew up in Washington State - right across the border from Vancouver - and love it there. People are exceedingly friendly, even when they’re making fun of my “American” accent. :>

  • Jeff @ DreamHost
  • DH Discussion Forum Admin