oni-kun Posted December 18, 2009 Share Posted December 18, 2009 You wrote it so if $emailMessage is blank, it won't send. $emailMessage will always be "\n----MESSAGE-----\n" even if they entered a message or not. You'd just need to check the POST not the variable. Try this: <?php if (isset($_POST['Name'])){ $emailTo = 'cm@chrismdesign.com'; $emailName = $_POST['Name']; $emailFrom = $_POST['Email']; $emailSubject = $_POST['Subject']; $emailMessage = "\n-----MESSAGE-----\n" . $_POST['Message']; $emailMessage .= "\n-----NAME-----\n" . $_POST['Name']; $emailMessage .= "\n-----EMAIL-----\n" . $_POST['Email']; if (!preg_match('/^([A-Z0-9\.\-_]+)@([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) { echo 'Please enter a valid email address'; } elseif (empty($emailName)) { echo 'Please enter your name'; } elseif (empty($emailSubject)) { echo 'Please enter a subject'; } elseif (empty($_POST['Message'])) { echo 'Please enter a message'; } else { if (!empty($emailFrom)) { $emailHeaders = 'FROM: <cm@chrismdesign.com>'; } /* Send Email */ if (mail($emailTo, $emailSubject, $emailMessage, $emailHeaders)) { echo 'You message has been sent!'; } else { echo 'There was an internal error whilst sending your email.<br>'; echo 'Please try again later.'; } } } ?> A simple mistake to make. Quote Link to comment https://forums.phpfreaks.com/topic/185522-problem-sending-email-with-php-form/page/2/#findComment-980170 Share on other sites More sharing options...
hatefulcrawdad Posted December 18, 2009 Author Share Posted December 18, 2009 You wrote it so if $emailMessage is blank, it won't send. $emailMessage will always be "\n----MESSAGE-----\n" even if they entered a message or not. You'd just need to check the POST not the variable. Try this ...code deleted for length... A simple mistake to make. OMG, thank you so much. What is with that guy trying to get headers defined when it already is? wierd. But anyway, you are a complete life saver. I am set with this contact form, not just gotta style the bitch. Quote Link to comment https://forums.phpfreaks.com/topic/185522-problem-sending-email-with-php-form/page/2/#findComment-980179 Share on other sites More sharing options...
oni-kun Posted December 18, 2009 Share Posted December 18, 2009 No problem! I spoke from experience when I first made a contact form.. Since your problem is solved, hit the 'Topic Solved' button on the bottom left of this thread.. We try to get as many users as we can to use it . EDIT: That guy doesn't know much about programming, Not sure why he babbles on like that. He's pretty good with some things though.. Quote Link to comment https://forums.phpfreaks.com/topic/185522-problem-sending-email-with-php-form/page/2/#findComment-980182 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.