Sending PHP email


Help! A few months ago, I switched my hosting from Godaddy to Dreamhost. Just transferred all the files over. I figured if it worked on Godaddy, it should work on Dreamhost. Didn’t realize that Dreamhost had more stringent email restrictions. I heard from a friend that I do a site for that he’s not getting any contact form messages. Checked with some others and they’re not getting any, either. I use the Oxygen template and here’s the PHP code:

$name = @trim(stripslashes($_POST[‘name’]));
$from = @trim(stripslashes($_POST[‘email’]));
$subject = @trim(stripslashes($_POST[‘subject’]));
$message = @trim(stripslashes($_POST[‘message’]));
$to = ‘’;//replace with your email

$headers = array();
$headers = “MIME-Version: 1.0”;
$headers .= “Content-type: text/plain; charset=iso-8859-1”;
$headers .= “From: {$name} <{$from}>”;
$headers .= “Reply-To: <{$from}>”;
$headers .= “Subject: {$subject}”;
$headers .= “X-Mailer: PHP/”.phpversion();

mail($to, $subject, $message, $headers);


Asked on another forum and they said to remove the second line with the from. Tried that and it didn’t work. Also tried changing it to:

[php]$from = ‘’; [/php]

Where the address is the email set up for the hosted site. Still nothing. Some suggested PHPmailer or Swiftmailer, which sound great, but need software installations and command line instructions, issued where I don’t know. I just want to email. PEAR doesn’t look any easier. What do I need to change above?

People claim that even Godaddy requires such changes now, but the last site I still have hosted there is still running fine, with the unmodified contact form still working after years. This is extremely frustrating.


There’s a minimal installation and basic SMTP example on the PHPMailer github page.


If installation instructions are there, I can’t find them. Downloaded the zip and looked in the Docs folder. It’s a lot of bash commands, none of which pertain to installation. I have no idea how to install Composer, if it even needs to be installed. Then there’s trying to modify the PHPmailer script to add all the form fields rather than just sending a fixed message.

Pretend I don’t know anything about coding PHP, which isn’t far from the truth. What do I need to change in the above script to make it work? Surely there must be some PHP wizards here. How did you get PHP mail scripts to work on Dreamhost?


I used the form templates I found here:

They work on DreamHost without any problem. I modified them to meet my needs.

The tutorial on that site is a good one; there are also plenty of how-to articles. If you are willing to Google what you don’t know (not just “how do I do this?”, but “what is this php command for and how does it work?”) and experiment, you can probably achieve what you need to and come out with some additional PHP knowledge and confidence.


Three more tips:

The “From:” header must be a valid account on your domain. It can be a “forward only” address, but for best results don’t forward it outside dreamhost. Some specific mail domains that I know don’t accept the forwards are gmail, yahoo, aol, and comcast appears to be hit or miss. That list is not all inclusive.

With whatever plugin you choose, set up SMTP for sending, especially if your using shared hosting for webservers. Like every other shared hosting provider, dreamhost’s shared servers do end up on RBL’s from time to time. One advantage at dreamhost tho, is you can set up your form to use SMTP and send from the mail server instead of sending from the webserver via mail(). If your on shared hosting in particular setting up SMTP sending is advantageous, your email server is much less likely to end up on an RBL list, and your email is much less likely to end up in a spam folder.

As far as the “To:” field of the email, it works best if it’s a dreamhost hosted email account. (i.e. the email never has to go outside dreamhost)


Thanks, Lakerat, but I’m leaving. Other than you, the prevailing attitude here is “Google, learn and help yourself because we’re not here to help you.” I’m not a web designer, just someone who adapts some templates for a few friends, and I don’t have time to learn PHP, json, bash, Composer, Javascript, etc. There were actually more people offering help on the other forum I tried, but they didn’t have specific experience with Dreamhost. I don’t know why they bother to have forums here when most people don’t want to help. No deep-linked URLs, just general links to home pages. No names of files to read, just “there’s a good tutorial.” Sorry if I disappoint with weak Google-fu.

Adios and thanks for you at least.