bramwolf Posted March 25, 2015 Share Posted March 25, 2015 Hey Guys! I was developing a contact based on Ryan's basic contact form. At first I had some problems getting all the data I wanted into the mail being sent, but I got that fixed. At some random point in developing it stopped sending the emails, which earlier it did very fast without any problems. I went back to how the code was when it was sending but since than couldn't get it to work again. I've looked over it a hundred times by now and can't find anything that would cause it to not send the e-mail. It even validates and gives the validation message, which it could only do after it sent the e-mail? Does anyone know what could be going on? You can find the form at: www.partyverhuursiroo.nl/bestellijst/ and here is the code I'm using ( I'm a php n0ob, plz be gentle ) Thanks in advance for your help! Bram Wolf <?php // set this to the email address you want to send to (or pull from a PW field) $emailTo = 'info@bramwolf.nl'; // or if not set, we'll just email the default superuser if(empty($emailTo)) $emailTo = $users->get($config->superUserPageID)->email; // set and sanitize our form field values $form = array(); $product = array(); $form["naam"] = $input->post->naam; $form["straatnaam"] = $input->post->straatnaam; $form["postcode"] = $input->post->postcode; $form["woonplaats"] = $input->post->woonplaats; $form["telefoon"] = $input->post->telefoon; $form["email"] = $input->post->email; $form["verhuurdatum"] = $input->post->verhuurdatum; $form["retourdatum"] = $input->post->retourdatum; $form["comments"] = $input->post->comments; $j = 0; foreach ($_COOKIE as $key => $val){ $cookies[] = array($key); $values[] = array($val); foreach ($pages->get('/assortiment')->children as $subpage ) { foreach ($subpage->artikelen as $artikel ) { if ($key == $artikel->id) { $j++; $product["artikel_aantal" . $j] = $_COOKIE[$key]; $product["artikel_naam" . $j] = $artikel->product_title; $totaal = $_COOKIE[$key] * $artikel->product_price; $product["artikel_prijs" . $j] = $totaal; } } } } // foreach ($product as $one => $two) { // echo " $one = $two <br>"; // } // initialize runtime vars $sent = false; $error = ''; // 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 = "<h3 class='error'>Controleer of alle velden zijn ingevuld</h3>"; } // if no errors, email the form results if(!$error) { $subject = "Bestelling van $form[naam]"; $message = ''; foreach($form as $key => $value) { $message .= "$key: $value\n"; } $message .= "\n \n"; $j++; $postcount = 1; while ($postcount < $j) { foreach($product as $key => $value) { if ($key == 'artikel_aantal' . $postcount ) { $message .= "$value x"; // echo $value . " x "; } if ($key == 'artikel_naam' . $postcount ) { $message .= "$value ="; // echo $value; } if ($key == 'artikel_prijs' . $postcount ) { $message .= "€ $value \n"; // echo " = € " . $value . "<br>"; } } $postcount++; } mail($emailTo, $subject, $message, "From: $form[email]"); $sent = true; } } if($sent) { echo "<h3>Hartelijk bedankt voor uw bestelling. Wij nemen zo spoedig mogelijk contact met u op!</h3>"; // or pull from a PW field } else { // encode values for placement in markup foreach($form as $key => $value) { $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8"); } // output the form echo <<< _OUT $error <form action="./" method="post"> <p class="form_p"> <label for="naam">Uw Naam</label><br /> <input type="text" id="naam" name="naam" size="60" value="$form[naam]" /> </p> <p class="form_p"> <label for="straatnaam">Straatnaam en huisnummer</label><br /> <input type="text" name="straatnaam" id="straatnaam" size="60" value="$form[straatnaam]" /> </p> <p class="form_p"> <label for="telefoon">Uw telefoon nummer</label><br /> <input type="text" name="telefoon" id="telefoon" size="60" value="$form[telefoon]" /> </p> <p class="form_p"> <label for="postcode">Uw postcode</label><br /> <input type="text" name="postcode" id="postcode" size="60" value="$form[postcode]" /> </p> <p class="form_p"> <label for="email">Uw Email adres</label><br /> <input type="email" name="email" id="email" size="60" value="$form[email]" /> </p> <p class="form_p"> <label for="woonplaats">Uw woonplaats</label><br /> <input type="text" name="woonplaats" id="woonplaats" size="60" value="$form[woonplaats]" /> </p> <p class="form_p"> <label for="verhuurdatum">Verhuur datum: </label><br /> <input type="text" id="verhuurdatum" name="verhuurdatum" value="$form[verhuurdatum]" /> </p> <p class="form_p"> <label for="retourdatum">Retour datum: </label><br /> <input type="text" id="retourdatum" name="retourdatum" value="$form[retourdatum]" /> </p> <p class="form_p"> <label for="comments">Comments</label><br /> <textarea id="comments" name="comments" rows="5" cols="60">$form[comments]</textarea> </p> <p class="form_p"><input type="submit" name="submit" value="Submit" /></p> </form> _OUT; } ?> Link to comment Share on other sites More sharing options...
adrian Posted March 25, 2015 Share Posted March 25, 2015 I see you are using mail() What version of PW are you running? If 2.5+ then you should be using WireMail() and I'd also recommend making use of one of the SMTP mail modules: http://modules.processwire.com/modules/wire-mail-smtp/ http://modules.processwire.com/modules/wire-mail-swift-mailer/ PHP's mail function is not awesome and you should use SMTP if possible it has a whole host of advantages, including reducing the likelihood that the email will be trapped as spam. 1 Link to comment Share on other sites More sharing options...
bramwolf Posted March 25, 2015 Author Share Posted March 25, 2015 Hey Adrian, Thanks for the quick reply. I changed my code into wireMail, but it still isn't sending. wireMail($emailTo, $subject, $message, "From: $form"); Also, it's weird that it doesn't send anymore although it used to send just fine using mail(). The messages aren't trapped in my spam or junk and for as far as I know my provider doesn't filter messages on forehand. Do you think installing one of the modules will fix my problem? Gr, Bram Link to comment Share on other sites More sharing options...
adrian Posted March 25, 2015 Share Posted March 25, 2015 If you don't have one of the smtp modules installed, then wireMail will still use php's mail function. I would try is to install one of the modules and see if it works. The other thing to try is run a php mail command in a php file outside of PW to make sure there are no issues with your server's mail function, but if you get SMTP running, then this isn't relevant, but might help to explain why things just stopped working. I would also try logging $emailTo, $subject, $message and $form to make sure they are still being populated as expected. Link to comment Share on other sites More sharing options...
bramwolf Posted March 25, 2015 Author Share Posted March 25, 2015 SOLVED After extensive chat with One.com support I found out that outgoing e-mail from adreses other than the domains will be blocked after about 20 e-mails. So when sending from a adres within the domain resulted in direct delivery.. I want to cry... Is there anywhere I can get a refund for those 4 hours of my life? Thanks for your help though.. Bram Wolf Link to comment Share on other sites More sharing options...
Martijn Geerts Posted March 25, 2015 Share Posted March 25, 2015 A lot of people think they can code all day long, but do they realise they're debugging most of the time.Welcome to the club... 3 Link to comment Share on other sites More sharing options...
iNoize Posted December 6, 2017 Share Posted December 6, 2017 On 25.3.2015 at 8:49 PM, bramwolf said: SOLVED After extensive chat with One.com support I found out that outgoing e-mail from adreses other than the domains will be blocked after about 20 e-mails. So when sending from a adres within the domain resulted in direct delivery.. I want to cry... Is there anywhere I can get a refund for those 4 hours of my life? Thanks for your help though.. Bram Wolf So how to solve this now ? Change the from adress ? Have the same Problem. But cant fix it ? Can you make an example ? pls Tnx Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted December 6, 2017 Share Posted December 6, 2017 My approach for reliably sending out system-based/transactional emails is to signup for Mailgun.com. It's free if you're sending out less than 10,000 emails per month. It will require you to put a credit card on file. I then use the Swift Mailer module to customize the SMTP settings and such:https://modules.processwire.com/modules/wire-mail-swift-mailer/ Make sure to setup the TXT records as well that Mailgun recommends. For example, if your site uses G-Suite for regular email and Mailgun for transactional emails, then this is what you'd need (refer to what Mailgun tells you upon signup; replace the IP with your server IP address, or adjust accordingly): v=spf1 ip4:123.456.789.123 include:_spf.google.com ~all v=spf1 include:mailgun.org ~all I've found this method to be extremely reliable, quick, painless and I like that the account is not tied to what might be a site's overall email system like G-Suite. It keeps things separate to prevent situations like this. (definitely read that link) 2 Link to comment Share on other sites More sharing options...
bramwolf Posted December 6, 2017 Author Share Posted December 6, 2017 2 hours ago, iNoize said: So how to solve this now ? Change the from adress ? Have the same Problem. But cant fix it ? Can you make an example ? pls Tnx Hi, I used these emails to send mails to the administrator of the site. So I wanted to send from example.com to info@example.com this just worked. But I was testen from example.com to info@bramwolf.nl, which was outside the domain and thus didn't work. Easiest way to check if the emails will arrive at the admin is to send a test email and ask for a confirmation from the admin email account holder. Good luck 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