ttmt Posted June 4, 2009 Share Posted June 4, 2009 Hi all I have a simple email script that shows a message when the email has been sent. The message uses the name used in the email form $message = "Thank you $name_field, we will be in touch soon."; This name could be two names - first name and last last name. Is it possible to split this string and just use the first name. I was thinking it might be possible to use the space character to determine the split. <?php $message = ""; if(isset($_POST['submit'])) { $errors = array(); $required_fields = array('name','email','message'); foreach($required_fields as $fieldname){ if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){ $errors[] = $fieldname; } } if(empty($errors)){ $to = "info@ttmt.org.uk"; $name_field = $_POST['name']; $email_field = $_POST['email']; $subject = "Email from Website"; $message = $_POST['message']; // $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; // mail($to, $subject, $body); $message = "Thank you $name_field, we will be in touch soon."; }else{ $message = "Please complete all fields."; } } ?> Quote Link to comment Share on other sites More sharing options...
Dtonlinegames Posted June 4, 2009 Share Posted June 4, 2009 <?php $name =explode(' ', $name_field); $firstname =$name[0]; $lastname=$name[1]; ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 Use trim on $name_field as well. Quote Link to comment 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.