Php contact form

Hi, I found an online php contact form which I love and works perfectly, AS LONG AS the email address I enter on the form (which the form uses to send the email from) is one that dreamhost recognizes (ie, one of mine that is hosted by Dreamhost). If I use my wife’s gmail address, the email never gets delivered. I believe this part of the php below which generates the email is what is causing problems, and I think that if I were able to change the sender to my address as opposed to the address that the user enters, it would work.

[php]// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>[/php]

Can anyone tell me how to do that? If you need the rest of the code I can provide it. Please note that I am very inexperienced with php, I just copy and paste to make things work so please be specific in your answers :slight_smile: thanks

lets say your dreamhost email is bob@floggle.com.
Then this might work:

//add your dreamhost email
$email_dh = "bob@floggle.com';
// create email headers
$headers = 'From: '.$email_dh."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

Thanks. When I changed my code to yours, I get an error (unexpected \ in the $headers line). However, without defining $email_dh, I just changed $email-from to $email_to which was defined earlier and it seems to work. I’m also investigating http://formmail.dreamhost.com/ which may be a more reliable alternative. Thanks again!

there is a typo in his code:

$email_dh = "bob@floggle.com’;

should be

$email_dh = ‘bob@floggle.com’;

Thanks. For whatever reason, the dreamhost servers seem to be blocking messages even when I use the dreamhost cgi script at formmail.dreamhost.com. Though it doesn’t look like that has been updated in awhile. Seems as long as I keep the sent from address to my own email which matches the domain, everything works fine.

This is not unexpected. You can only mail from scripts to your domain’s email, in order to prevent people from spamming :confused:

http://www.dreamhost.com/anti-spam-policy/

the workaround (if you need it) is to use SMTP to send mail.