Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member BallardStudio's Avatar
    Join Date
    Jul 2011
    Posts
    143
    Member #
    28552
    Liked
    6 times

    PHP Email - Not Returning Subject In Subject Line

    I am having the trouble with this source code. Can't figure out why the subject line isn't populating with the subject. Help is very much appreciated. I've been at this for quite some time.

    <?php
    $emailTo = 'example@example.com';
    if($subject!=""){
    $subject =$_REQUEST['subject'];
    }else{
    $subject = 'subject';
    }
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $email=$_REQUEST['subject'];
    $msg=$_REQUEST['msg'];

    $body = "Name: $name \n\nEmail: $email \n\nWebsite: $website \n\nMessage: $msg";
    $headers = 'From: '.$name.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

    mail($emailTo, $subject, $body, $headers);
    ?>


    <form id="contact" action="process.php">
    <fieldset>
    <span class="error" id="name_error">Please enter name !</span>
    <span class="error" id="email_error">Please enter email address !</span>
    <span class="error" id="email_error2">Please enter valid email address !</span>
    <span class="error" id="msg_error">Please enter message !</span>
    <label for="name" id="name_label">Name (required)</label>
    <input type="text" name="name" id="name" size="50" value="" class="text-input" />
    <label for="email" id="email_label">Email (required)</label>
    <input type="text" name="email" id="email" size="50" value="" class="text-input" />
    <label for="subject" id="subject_label">Subject</label>
    <input type="text" name="subject" id="subject" size="50" value="" class="text-input" />
    <label for="msg" id="msg_label">Message</label>
    <textarea rows="10" name="msg" id="msg" class="text-input"></textarea>
    <br />
    <input type="submit" name="submit" class="button" id="submit_btn" value="Send Message"/>
    </fieldset>
    </form>
    I'm an art director crossing paths between print and web design.
    http://www.ballardstudio.com

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    First, use POST instead of REQUEST ... and you define that in the <form> tag also .... method="post"

    You also had this:
    $email=$_REQUEST['email'];
    $email=$_REQUEST['subject'];

    I changed to:
    $email=$_REQUEST['email'];
    $subject=$_REQUEST['subject'];

    My modifications below. No validation or security issues are addressed here. Just the modifications that should make it work. ...


    <?php
    $emailTo = 'example@example.com';
    $subject = 'subject';

    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $msg=$_POST['msg'];

    $body = "Name: $name \n\nEmail: $email \n\nWebsite: $website \n\nMessage: $msg";
    $headers = 'From: '.$name.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

    if(mail($emailTo, $subject, $body, $headers)){
    // mail sent
    }
    else{
    echo "Mail did not send for some reason";
    }
    ?>



    <form id="contact" action="process.php" method="post">
    <fieldset>
    <span class="error" id="name_error">Please enter name !</span>
    <span class="error" id="email_error">Please enter email address !</span>
    <span class="error" id="email_error2">Please enter valid email address !</span>
    <span class="error" id="msg_error">Please enter message !</span>
    <label for="name" id="name_label">Name (required)</label>
    <input type="text" name="name" id="name" size="50" value="" class="text-input" />
    <label for="email" id="email_label">Email (required)</label>
    <input type="text" name="email" id="email" size="50" value="" class="text-input" />
    <label for="subject" id="subject_label">Subject</label>
    <input type="text" name="subject" id="subject" size="50" value="" class="text-input" />
    <label for="msg" id="msg_label">Message</label>
    <textarea rows="10" name="msg" id="msg" class="text-input"></textarea>
    <br />
    <input type="submit" name="submit" class="button" id="submit_btn" value="Send Message"/>
    </fieldset>
    </form>


  4. #3
    Senior Member BallardStudio's Avatar
    Join Date
    Jul 2011
    Posts
    143
    Member #
    28552
    Liked
    6 times
    The emails that are being sent still don't show the subject. They show the website name instead of the subject in the field.
    I'm an art director crossing paths between print and web design.
    http://www.ballardstudio.com

  5. #4
    Senior Member BallardStudio's Avatar
    Join Date
    Jul 2011
    Posts
    143
    Member #
    28552
    Liked
    6 times
    Here's where the problem was. Line 10 was missing the subject tag.

    Old Tag
    $body = "Name: $name \n\nEmail: $email \n\nWebsite: $website \n\nMessage: $msg";

    New Tag
    $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nMessage: $msg";

    I removed the website because it wasn't needed.
    I'm an art director crossing paths between print and web design.
    http://www.ballardstudio.com

  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Good eyes ... I didn't see that one.



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:11 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com