sher4 Posted March 17, 2014 Share Posted March 17, 2014 Hi and thanks in advance if you are able to help me. I am new to php and using a tempate with the following code which sends me the email OK but the sent email does not show the name and I can't work put why..! HTML FORM <div class="contact-form"> <form class="contact-form" method="post" action="/"> <p class="contact-form-name"> <label for="name">Name <span class="required">*</span></label> <input type="text" aria-required="true" size="30" value="" name="name" id="name" class="form-control" placeholder="Your Name"> </p> <p class="contact-form-email"> <label for="email">Email <span class="required">*</span></label> <input type="email" aria-required="true" size="30" value="" name="email" id="email" class="form-control" placeholder="Your email"> </p> <p class="contact-form-subject"> <label for="subject">Subject</label> <input type="text" size="30" value="" name="subject" id="subject" class="form-control" placeholder="Your Subject"> </p> <p class="contact-form-message"> <label for="message">Comment</label> <textarea aria-required="true" rows="8" cols="45" name="message" id="message" class="form-control" placeholder=""></textarea> </p> <p class="contact-form-submit"> <input type="submit" value="Send Your Message" id="contact_form_submit" name="contact_submit" class="theme_btn"> </p> </form> </div> contact-form.php <?php //Specify default values //Your E-mail $your_email = 'email@mymail.com'; //Default Subject if 'subject' field not specified $default_subject = 'From My Contact Form'; //Message if 'name' field not specified $name_not_specified = 'Please type a valid name'; //Message if 'message' field not specified $message_not_specified = 'Please type a vaild message'; //Message if e-mail sent successfully $email_was_sent = 'Thanks, your message successfully sent'; //Message if e-mail not sent (server not configured) $server_not_configured = 'Sorry, mail server not configured'; //Contact Form Processing $errors = array(); if(isset($_POST['message']) and isset($_POST['name'])) { if(!empty($_POST['name'])) $sender_name = stripslashes(strip_tags(trim($_POST['name']))); if(!empty($_POST['message'])) $message = stripslashes(strip_tags(trim($_POST['message']))); if(!empty($_POST['email'])) $sender_email = stripslashes(strip_tags(trim($_POST['email']))); if(!empty($_POST['subject'])) $subject = stripslashes(strip_tags(trim($_POST['subject']))); //Message if no sender name was specified if(empty($sender_name)) { $errors[] = $name_not_specified; } //Message if no message was specified if(empty($message)) { $errors[] = $message_not_specified; } $from = (!empty($sender_email)) ? 'From: '.$sender_email : ''; $subject = (!empty($subject)) ? $subject : $default_subject; $message = (!empty($message)) ? wordwrap($message, 70) : ''; //sending message if no errors if(empty($errors)) { if (mail($your_email, $subject, $message, $from)) { echo $email_was_sent; } else { $errors[] = $server_not_configured; echo implode('<br>', $errors ); } } else { echo implode('<br>', $errors ); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/287022-email-issue-name-not-showing-in-sent-email/ Share on other sites More sharing options...
ginerjm Posted March 17, 2014 Share Posted March 17, 2014 Define 'name' please. And please use code tags for your postings Quote Link to comment https://forums.phpfreaks.com/topic/287022-email-issue-name-not-showing-in-sent-email/#findComment-1472876 Share on other sites More sharing options...
micah1701 Posted March 17, 2014 Share Posted March 17, 2014 The code does not post the senders name into the message body of the e-mail. The line: $message = stripslashes(strip_tags(trim($_POST['message']))); sets the variable "$message" with the "Message" form field that has been sent from the form Then, the line that sends the emal is: if (mail($your_email, $subject, $message, $from)) { notice it just passes that "$message" variable along. No where in there is the persons name ever attached to the message. Quote Link to comment https://forums.phpfreaks.com/topic/287022-email-issue-name-not-showing-in-sent-email/#findComment-1472924 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.