chome4 Posted July 24, 2019 Share Posted July 24, 2019 Got this working script that sends email via a form: <?php if(empty($_POST) === false) { $errors = array(); $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; if(empty($name) === true || empty($email) === true || empty($message) === true) { $errors[] = 'name, email and message are required!'; } else { if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'Not valid email'; } if (ctype_alpha($name) === false) { $errors[] = 'name contain letters!'; } } if(empty($errors) === true) { mail('XXXXXXX@gmail.com','contact form',$message, 'From: '.$email); header('Location: index.php?sent'); exit(); } } ?> Problem is, I want a bar to appear saying 'Message Sent. We Will Contact You Shortly'. I'm brand new to php and followed a tutorial for the above. It's a simple form that I understand, apart from the code needed for confirmation! Please can someone offer any assistance. Thanks in advance...... Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/ Share on other sites More sharing options...
ginerjm Posted July 24, 2019 Share Posted July 24, 2019 First - do you know that what you have so far actually works??? Your 'from' address has to be valid for the mail server to use. You're allowing the user to provide it which is probably not what you want to have happen. A bar? You mean like a moving 'progress' bar? Or just a 'line' of text? Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/#findComment-1568666 Share on other sites More sharing options...
benanamen Posted July 24, 2019 Share Posted July 24, 2019 I would encourage you to continue to learn. As you get better you will recognize that tutorials such as the one you followed was very poorly done. Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/#findComment-1568667 Share on other sites More sharing options...
ginerjm Posted July 24, 2019 Share Posted July 24, 2019 (edited) Regarding your edits: if (ctype_alpha($name) === false) { $errors[] = 'name contain letters!'; } Do you WANT letters or not? As a newbie how about this: if (!ctype_alpha($name)) $errors[] = 'Name must be all alphabetic'; And this could be different: if(empty($errors)) { if (mail('XXXXXXX@gmail.com','contact form',$message, 'From: '.$email)) { header('Location: index.php?sent'); exit(); } else { echo "Message not sent"; exit(); } } Note the use of separate physical lines for each line of code. Combining them makes for troublesome reading down the road. Trust me. Also - the php mail function is not the greatest mail tool. It only offers a boolean response and that can be wrong without you knowing it. Edited July 24, 2019 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/#findComment-1568668 Share on other sites More sharing options...
chome4 Posted July 24, 2019 Author Share Posted July 24, 2019 The contact form actually works! Here's a link to the full site from which it comes: http://test.ericfinlayartist.co.uk/ I've removed my email but just tested it and it works, no confirmation, of course. Yes, I just want a line of text. I can format it with CSS later. Yep, still learning, but have been asked to help a friend out who wants the site. She understands! Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/#findComment-1568669 Share on other sites More sharing options...
ginerjm Posted July 24, 2019 Share Posted July 24, 2019 I've shown you how things could be written better. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/#findComment-1568670 Share on other sites More sharing options...
cyberRobot Posted July 24, 2019 Share Posted July 24, 2019 In case you're not aware, you'll likely experience problems down the road (if not already) with letting people supply the "From" argument for the mail function. The server that sends the message is only going to be authorized to send email from certain domains. Sending messages from domains it's not authorized to use (e.g. gmail.com) will result in a higher chance of being sent to spam...or being dropped altogether without a warning to the sender, recipient, or your server. It just gets dropped. Whether it marked as spam or dropped is up to the server responsible for the domain being spoofed (which is what your code is doing) and/or the email provider used by the person receiving the message. Quote Link to comment https://forums.phpfreaks.com/topic/309018-where-to-place-confirmation-code/#findComment-1568672 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.