Php mail contact form issue


#1

Hello. I have emailed support about this issue, but I am unable to get my php mail contact form working. I just switched to Dreamhost and it was working on my previous host.

I emailed the creator of the form and he says that all I need to do is add my email on line 26 ($recievers_email = "via@woolsies.com";).

All of the messages I send with this form are not coming through. Any help will be much appreciated!

Here is my current contactform.php

[code]<?php
function is_valid_email($vemail) {
$result = TRUE;
if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,4})$", $vemail)) {
$result = FALSE;
}
return $result;
}
//if “email” is filled out, send email
if (isset($_REQUEST[‘email’]) && $_REQUEST[‘email’] != ‘’ && $_REQUEST[‘name’] != ‘’ && $_REQUEST[‘message’] != ‘’
&& is_valid_email($_REQUEST[‘email’]))
{
//send email
$email = $_REQUEST[‘email’] ;
$name = $_REQUEST[‘name’] ;
$subject = $_REQUEST[‘subject’] ;
$message = $_REQUEST[‘message’] ;
$recievers_email = "via@woolsies.com";

mail($recievers_email, "$subject",
$message, "From:" . $email);
echo "<p class='form_success'>Message sent! Thank you!</p><p class='form_success_sub'>We'll reply as soon as possible.</p>";

}
else
{
//if “email” is not filled out, display the form
if(!is_valid_email($_REQUEST[‘email’]))
{
echo “

Please, insert an email address.

”;
}
else if($_REQUEST[‘name’] == ‘’)
{
echo “

Please, write your name.

”;
}
else if($_REQUEST[‘message’] == ‘’)
{
echo “

Please, leave your message.

”;
}
}
?> [/code]

#2

We don’t allow you to send email ‘from’ a domain that isn’t yours.

So if your domain is woolsies.com, all email in those forms has to come from woolsies.com.

You could set the users email as the reply-to


#3

Thanks for the info. practically speaking, I don’t understand what that means I should do to make the code work. I currently have the email set as via@woolsies.com (per the php developers instruction). Do I need to have the entire code re-written, or is there a way I can fix it by changing a couple items?


#4

The short version is you’re having the email sent ‘from’ the address the person filling in the form uses because of darn dirty spammers: http://www.dreamhoststatus.com/2012/04/04/improvements-to-outgoing-spam-prevention-policy/

So if your script is at woolsies.com/contact.php, then email must be ‘from’ woolsies.com. We talk a little about this here : http://wiki.dreamhost.com/PHP_mail() – Thankfully! This is not horrible to fix :slight_smile:

Go to the //send email section and replace it with this:

{
        //send email
        $to = "via@woolsies.com";
        $subject = $_REQUEST['subject'] ;
        $fromemail = $_REQUEST['email'] ;
        $fromname = $_REQUEST['name'] ;

        // compose headers
        $headers = "From: ".$to."\r\n";
        $headers .= "Reply-To: ".$fromemail." <".$fromname.">\r\n";
        $headers .= "X-Mailer: PHP/".phpversion();

        // compose message
        $message = $_REQUEST['message'] ;

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

        echo "<p class='form_success'>Message sent! Thank you!</p><p class='form_success_sub'>We'll reply as soon as possible.</p>";
}

That will send email to via@woolsies.com and while it will come ‘from’ that email, when you press reply, the reply-to headers will pull in the from email.