Jump to content

Recommended Posts

Posted

I have a built in, well versed loathing for contact forms!

Okay, did this little contact form which I include via hanna code. This is not my code.

On the dev server it worked fine.

On the production server, it seems to work (as far as I know) but I am not receiving mail.

I have tried setting up spf records.

I have changed the destination email address to something different (different domain) but that still doesn't work.

I have messed a little bit with wiremail and smtp, but I am not sure what I am doing. At the moment it is back to mail()

Not throwing any errors.

Anyone got any bright ideas?

Here is the basic code:

$sent = false;
$error = '';
$emailTo = $pages->get("/settings/")->contact_email; // or pull from PW page field

// sanitize form values or create empty
$form = array(
    'fullname' => $sanitizer->text($input->post->fullname),
    'email' => $sanitizer->email($input->post->email),
    'phone' => $sanitizer->text($input->post->phone),
    'comments' => $sanitizer->textarea($input->post->comments),
    ); 

// check if the form was submitted
if($input->post->submit) {
    
    // determine if any fields were ommitted or didn't validate
    foreach($form as $key => $value) {
        if(empty($value)) $error = "<p class='error'>Please check that you have completed all fields.</p>";
    }
if($input->post->my_message) {
    $error = "Sorry, there has been a problem";
}
    // if no errors, email the form results
    if(!$error) {
        $msg = "Full name: $form[fullname]\n" . 
               "Email: $form[email]\n" .
               "Phone: $form[phone]\n" . 
               "Comments: $form[comments]"; 

        mail($emailTo, "Contact Form", $msg, "From: $form[email]");

        // populate body with success message, or pull it from another PW field
        echo "<h2>Thank you, your message has been sent.</h2>"; 
        $sent = true;   
    }
}

if(!$sent) {

    // sanitize values for placement in markup
    foreach($form as $key => $value) {
        $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8"); 
    }

    // append form to body copy
    echo <<< _OUT

        $error
        <form action="./" method="post" class="shortform">
<div class="row">
    <div class="columns">
    All Fields Required
    </div>
    <div class="columns">
        <label for="fullname">Your Name
        <input placeholder="Your Name" type="text" id="fullname" name="fullname" value="$form[fullname]" />
        </label>
    </div>
</div>
<div class="row">
    <div class="columns">
        <label for="email">Your Email
        <input placeholder="Email" type="email" name="email" id="email" value="$form[email]" />
        </label>
    </div>
</div>
<div class="row">
    <div class="columns">
        <label for="phone">Your Phone
        <input placeholder="Phone" type="text" name="phone" id="phone" value="$form[phone]" />
        </label>
    </div>
</div>
<div class="row">
    <div class="columns">
        <label for="comments">Comments
        <textarea placeholder="Comments" id="comments" name="comments">$form[comments]</textarea>
        </label>
    </div>
</div>
<div class="row">
    <div class="columns">
        <input class="button small large-12" type="submit" name="submit" value="Submit" />
    </div>
</div>

        </form>

_OUT;

}
  • Like 1
Posted

Hi Martijn

It worked fine on my local ubunto/webmin box.

It is not working on the professional shared production server.

Hi Adrian

Yes, I installed horsts smpt, but I am not sure I set it up properly - as in, what should I change on the code?

Posted

Have you tried creating reverse DNS records for the domain you're sending from? This will probably have to be done by the ISP if this is your issue.

ip 193.405.123.123 -> yourdomain.com

Posted

I have just tried the SwiftMailer module - when I try to send the test message is says "A Test message was sent to 0 recipients."

That is not encouraging.

Posted

Sometimes reverse DNS is used by mail servers to authenticate that the sending IP address actually matches the domain it proclaims to come from. The issue you may have is you're using shared hosting one IP address may be used to host multiple domains making reverse DNS difficult. You can look to see if it is set up on a site like this:

http://mxtoolbox.com/ReverseLookup.aspx

but for shared hosting this may not be the answer.

I've not seen it but I can probably assume horst's module uses a separate mailing provider to send the mail rather than the site's own php.

Not sure I've really helped much but it does as least give another avenue to explore.

Posted

@Joss: at first I would debug what's going on with the php mail function. If it works on your local host and not on the live, there must be a difference.

I would hack into the code and store the return from the mail() function:

$ret = mail($emailTo, "Contact Form", $msg, "From: $form[email]");
echo "<pre>\n return from mail() is: ";
var_dump($ret);
die("\n\nDebugExit in file " . __FILE__ . " at line: " . __LINE__);
  • Like 1
Posted

If you want to use one of the SMTP modules, you have to install only one and setup the config screen.

If I remember right, both have a testconnection button / link in the config screen what lets you test your settings.

After this is successfull you can change the mail() function in your code to something like:

$ret = wireMail($emailTo, $form[email], "Contact Form", $msg);
Posted

The problem with the SMTP approach was that Google starting sending me mails saying someone was trying to hack my account.... :)

  • Like 1
Posted

Hi Horst

Tried your modification and it returned:

return from mail() is: bool(true)


DebugExit in file /xxxxxxxxxxxxxx/site/assets/cache/HannaCode/contactshort.php at line: 35

Posted

use this for testing: $ret = mail($emailTo, "Contact Form", $msg);  // no additional header for FROM, your shared host will create a generic one

Posted

okay, still nothing arrived.

Knowing my luck, the entire lot of tests will all arrive at christmas....

  • Like 2
Posted

what is set for TO (recipient) at runtime?

    echo "<pre>\n emailTo: ";
    var_dump($emailTo);
    die("\n\nDebugExit in file " . basename(__FILE__) . " at line: " . __LINE__);
Posted

@ kongondo: I am checking my spam folder. I have set up SPF already, but for testing I am sending to a different email address just incase that is failing for some reason.


@horst

its outputting the correct address

Posted

Yep - but that is more likely to suffer problems, so I am not doing that while testing so I can eliminate those issues.

Posted

Okay, I now have it working ... er, sort of.

It turned out that the tmp partition on the box was full, which was why it was not sending mail. This must have been affecting everyone on the box, of course - a minus point for Kualo there, who normally get good reviews. But then, at least they found the problem....

Currently using mail() direct on the script - not actually getting anything else working at the moment, but at least I have got the form working

:)

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...