Joss Posted September 22, 2014 Share Posted September 22, 2014 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; } 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 22, 2014 Share Posted September 22, 2014 Hi Joss, Do you have a mac ? If so, mail is disabled by default. I've re-written instructions to enable it Link to comment Share on other sites More sharing options...
adrian Posted September 22, 2014 Share Posted September 22, 2014 Hey Joss, Have you tried WireMail with horst's or teppo's plugins to make use of SMTP, instead of mail? Link to comment Share on other sites More sharing options...
Joss Posted September 22, 2014 Author Share Posted September 22, 2014 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? Link to comment Share on other sites More sharing options...
davo Posted September 22, 2014 Share Posted September 22, 2014 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 Link to comment Share on other sites More sharing options...
Joss Posted September 22, 2014 Author Share Posted September 22, 2014 @Davo The site is parked on a commercial host - how would I do that? Link to comment Share on other sites More sharing options...
Joss Posted September 22, 2014 Author Share Posted September 22, 2014 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. Link to comment Share on other sites More sharing options...
davo Posted September 22, 2014 Share Posted September 22, 2014 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. Link to comment Share on other sites More sharing options...
kongondo Posted September 23, 2014 Share Posted September 23, 2014 Maybe go back to mail() and do simple tests as recommended here is SO 1 Link to comment Share on other sites More sharing options...
horst Posted September 23, 2014 Share Posted September 23, 2014 @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__); 1 Link to comment Share on other sites More sharing options...
horst Posted September 23, 2014 Share Posted September 23, 2014 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); Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 The problem with the SMTP approach was that Google starting sending me mails saying someone was trying to hack my account.... 1 Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 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 Link to comment Share on other sites More sharing options...
horst Posted September 23, 2014 Share Posted September 23, 2014 (edited) mail() returns true (== successful), did you get the mail? Edited September 23, 2014 by horst Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 Nope Oh, I have set the send address to something different to the domain. Link to comment Share on other sites More sharing options...
horst Posted September 23, 2014 Share Posted September 23, 2014 Yes, let out the additional "From: $form" and try with the generic one from the shared host! Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 Yes, let out the additional "From: $form" and try with the generic one from the shared host! Er ... where is that? By the way, I don't use email on the host, they are all google apps ones Link to comment Share on other sites More sharing options...
horst Posted September 23, 2014 Share Posted September 23, 2014 use this for testing: $ret = mail($emailTo, "Contact Form", $msg); // no additional header for FROM, your shared host will create a generic one Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 okay, still nothing arrived. Knowing my luck, the entire lot of tests will all arrive at christmas.... 2 Link to comment Share on other sites More sharing options...
kongondo Posted September 23, 2014 Share Posted September 23, 2014 Why is my PHP script not sending emails? http://www.html-form-guide.com/email-form/php-script-not-sending-email.html Link to comment Share on other sites More sharing options...
horst Posted September 23, 2014 Share Posted September 23, 2014 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__); Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 @ 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 Link to comment Share on other sites More sharing options...
davo Posted September 23, 2014 Share Posted September 23, 2014 Have you tried sending the email to an email on the same domain as the site? Link to comment Share on other sites More sharing options...
Joss Posted September 23, 2014 Author Share Posted September 23, 2014 Yep - but that is more likely to suffer problems, so I am not doing that while testing so I can eliminate those issues. Link to comment Share on other sites More sharing options...
Joss Posted September 24, 2014 Author Share Posted September 24, 2014 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 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now