linnington Posted December 4, 2012 Share Posted December 4, 2012 I have a rather bizarre problem with a script I use for sending automated emails. The script is: <?php $formSubmitted = isset($_POST['submitted']); $submitSuccess = false; if (formSubmitted) { function spam_scrubber($value) { $very_bad = array('to:','cc:','bcc:','content-type:','mime-version:','multipart-mixed:','content-transfer-encoding:'); foreach ($very_bad as $v) { if(stripos($value,$v) !== false) return ''; } return trim(strip_tags($value)); }//end of spam_scrubber $scrubbed = array_map('spam_scrubber',$_POST); if (!empty($scrubbed['customerName']) && !empty($scrubbed['customerQuery']) && (!empty($scrubbed['phone']) || !empty($scrubbed['emailAddress']))) { $submitSuccess = true; if (!empty($scrubbed['emailAddress'])) { $emailAddress = $scrubbed['emailAddress']; if (!strstr($emailAddress,'@') || !strstr($emailAddress,'.')) { $submitSuccess = false; } } if ($submitSuccess) { $body = "Customer's name: {$scrubbed['customerName']}\nCustomer's phone number: {$scrubbed['phone']}\nCustomer message: {$scrubbed['customerQuery']}"; $body = wordwrap($body,70); $from = "no-reply@lbi-beach-house.com"; if (!empty($scrubbed['emailAddress'])) { $from = $scrubbed['emailAddress']; } mail('my@emailaddress.com','Message via website from ' . $scrubbed['customerName'],$body,"From: ".$from); header( 'Location: thank-you.php' ) ; } } }//end of formSubmitted ?> The problem is with the emailAddress submitted. During testing, if I use an email address from the domain @wsgfl.org.uk then the script fails to send the email (yet it redirects to the thank-you page). It's bizarre because I only have to change the submitted domain by one letter and it works. It seems to have nothing to do with the length of the address or the number of dots in the address. Anyone got any ideas? I've checked my spam filter - it's not that! Many thanks for your advice in advance. Quote Link to comment https://forums.phpfreaks.com/topic/271607-bizarre-email-problem/ Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2012 Share Posted December 4, 2012 Your redirect happens regardless of whether mail() succeeds or fails. There is no way for php to know whether the mail was sent or not, only if mail() successfully transferred it to the MTA. Quote Link to comment https://forums.phpfreaks.com/topic/271607-bizarre-email-problem/#findComment-1397560 Share on other sites More sharing options...
Christian F. Posted December 5, 2012 Share Posted December 5, 2012 The only thing you can do, to accurately validate an e-mail as existing, is to contact the mail-server. Note that this will be a slow process, and add a noticeable amount of time to your processing. So I don't recommend doing it, unless it's vital that you always send e-mails to an existing e-mail address. Quote Link to comment https://forums.phpfreaks.com/topic/271607-bizarre-email-problem/#findComment-1397641 Share on other sites More sharing options...
gizmola Posted December 5, 2012 Share Posted December 5, 2012 What operating system is the server you are running this code on? Quote Link to comment https://forums.phpfreaks.com/topic/271607-bizarre-email-problem/#findComment-1397645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.