I'm very new to php and am having trouble with my send-mail.php file which is being hosted on dreamhost.
// site owner
$to = trim( $_POST['to'] );
$subject = trim( $_POST['subject'] );
// contact form fields
$name = trim( $_POST['name'] );
$email = trim( $_POST['email'] );
$message = trim( $_POST['message'] );
// check for error
$error = false;
if ( $name === "" )
{
$error = true;
}
elseif ( $email === "" )
{
$error = true;
}
elseif ( $message === "" )
{
$error = true;
}
// end check for error
// no error send mail
if ( !$error )
{
$body = "Name: $name
Email: $email
Message: $message";
$headers = 'From: ' . $name . ' <' . $email . '> ' . "
" . 'Reply-To: ' . $email;
mail( $to, $subject, $body, $headers );
echo 'success';
}
else
{
echo 'error';
}
// end no error send mail
?>
So this won't work on DreamHost because of their anti-spam filters.
They said this
The FROM address needs to belong to the domain (ie @mydomain.ie)
Once that is changed in the form settings, mail should be able to send correctly. This change was done to help prevent spam that was coming from the server:
http://dhurl.org/20b
If you would still like to keep the user inputted e-mail address, you would need to set it to be the REPLY-TO address instead of the FROM address.
I'm totally new to php and every time I try to edit the code, with reference to the DreamHost wiki, I end up breaking the thing!
I would really appreciate it if someone could help me out.
The FROM address needs to belong to the domain
that's pretty much what it is about. If they did their job right, there is no way to circumvent this.
You can set the Reply-to
header if you want any responses to be sent to someone else.
Its due to the host creating restrictions.
Simply use an email from your domain (e.g. noreply@yourdomain.com) for the email field, and just use the Reply-To as intended:
$name . ' <noreply@yourdomain.com> ' . "
" . 'Reply-To: ' . $email
Your emails should now be sent.