PHP mail() through Dreamhost


#1

Greetings!

My company uses dreamhost for several websites and we also use dreamhost to host our email for redrhinomg.com.

We actually host the webserver at our office and everything works great except when I’m trying to send auto emails.

Using php and the basic mail(), I’ve modified the .ini settings to have:
SMTP: mail.redrhinomg.com
smtp_port: 587

When trying to send the email I get the following error:

mail() [function.mail]: SMTP server response: 554 5.7.1 <unknown[66.0.107.146]>: Client host rejected: Access denied

I’m assuming because the email is originating form my server (66.0.107.146) and the dreamhost email server is rejecting?

The test php code is as follows:

$to = ‘ryan@gmail.com’;
$subject = ‘Test from ryan’;
$message = ‘test’;
$headers = ‘From: ryan@redrhinomg.com’ . “\r\n” .
‘Reply-To: ryan@redrhinomg.com’ . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();

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

Thanks for your help!


#2

I ran a couple tests and sorted this much out:

<?php

$to = "ryan@gmail.com";

$headers = "From: ryan@redrhinomg.com\r\n";
$headers .= "Reply-To: ryan@redrhinomg.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion()"\r\n";

$subject = "Test from Ryan";
$message = "This is a test.";

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

That seems to work for me, though I’m using gmail as my email here. Is the email.php (or whatever) file on your DH server or on your own webhost? I’m assuming webhost.


#3

The webserver is hosted in our office. So the A record in our DNS file on dreamhost points here. But we are using Dreamhost for the mail for the URL.

So the email is originating here at my office and I’ve setup our PHP server to use dreamhost for the smtp. Which is not working, but I’m hoping it will.

My guess is that I need to use a more advanced mail feature (Pear: Mail?) which allows me to plug in authentication info during the send?


#4

Ah, yeah, you’d need to authenticate, thanks to those darn spammers.

http://wiki.dreamhost.com/PHPMailer should do it.


#5

Awesome, that worked. Thanks buddy!