WordPress.org

Ready to get started?Download WordPress

Forums

Contact form - how to get subject line displayed in received e-mail (1 post)

  1. naastje
    Member
    Posted 1 year ago #

    Hey there,

    Do you know how to get the subject line being displayed in the received message (subject is not required) I have this code in my contact page template:

    if($_POST[sent]){
     $error = "";
     if(!trim($_POST[your_name])){
     $error .= "<p>Please enter your name</p>";
     }
     if(!filter_var(trim($_POST[your_email]),FILTER_VALIDATE_EMAIL)){
     $error .= "<p>Please enter a valid email address</p>";
     }
     if(!trim($_POST[your_message])){
     $error .= "<p>Please enter a message</p>";
     }
     if(!$error){
     $email = wp_mail(get_option("admin_email"),trim($_POST[your_name])." sent a message from ".get_option("blogname"), stripslashes(trim($_POST[your_message])),"From: ".trim($_POST[your_name])." <".trim($_POST[your_email]).">\r\nReply-To:".trim($_POST[your_email]));
     }
    }

    and this is the form:

    ?php if($email){ ?>
     <p><strong>Message sent. Thank you.</strong></p>
     <?php } else { if($error) { ?>
     <p><strong>Your message has not been sent</strong><p>
     <?php echo $error; ?>
     <?php } else { the_content(); } ?>
     <form action="<?php the_permalink(); ?>" id="contact_me" method="post">
     <input type="hidden" name="sent" id="sent" value="1" />
     <div id="form">
     <div id="label">Name*</div>
     <div id="input-field"><input type="text" name="your_name" id="your_name" value="<?php echo $_POST[your_name];?>" /></div>
     <div id="label">e-mail*</div>
     <div id="input-field"><input type="text" name="your_email" id="your_email" value="<?php echo $_POST[your_email];?>" /></div>
     <div id="lebel">Subject</div>
     <div id="input-field"><input type="text" name="your_subject" id="your_subject" value="<?php echo $_POST[your_subject];?>" /></div>
     </div>

    I would like to have the e-mails that I will received look something like

    [name] sent you a message from blog (as the header)

    Subject:
    (and message below)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.