Advanced Search

Results 1 to 6 of 6

Thread: Customize subject line in received emails

  1. #1
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Customize subject line in received emails

    Hello,
    I want to change the default subject line I receive from my contact form

    from:
    [ No Subject ]
    to:
    You have an inquiry

    Can that be done in my php form page? Do I also have to have it the html page?

    Thanks,
    Mary Jo

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    The subject is an option when using the mail() function:
    Code:
    bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
    Jeremy | jfein.net

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    But of course if you are using some other method of sending the email, the subject may need to be set another way. We'd need to see your code to help with that.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your reply. Here is the code.

    My wish is to have the subject filled in with the text "You have an inquiry from the website".


    <?php

    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $user_comments = $_POST['comments'];

    $myemail = "msajdowitz@yahoo.com";

    $comments = "
    Your contact form has been submitted by:

    Name: $name
    Phone: $phone
    Email: $email
    Comments:
    =======================================
    $user_comments
    =======================================
    ";

    $extraheaders = "From: $email\n\r Email sent from: $email\n\r";

    if (! mail($myemail, $subject, $comments, $extraheaders))
    echo "Mail did not send for some reason.";

    header("Location: thankYou.html");

    ?>
    ________________________________________________________
    Here is the html of the form if you need it.

    <div id="cForm">
    <form id="form1" name="form1" method="post" action="contactInfo.php">
    <span id="sprytextfield1">
    <label for="name">Your Name: <span class="astric">*</span></label>
    <input name="name" type="text" id="name" size="30" />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span>
    <p><span id="sprytextfield3">
    <label for="phone">Your Phone: <span class="astric">*</span></label>
    <input name="phone" type="text" id="phone" size="30" />
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
    </p>
    <p>
    <label for="email">Your Email: &nbsp;&nbsp;</label>
    <input name="email" type="text" id="email" size="30" />
    </p>
    <p>Comments or Questions:</p>
    <p>
    <label for="comments"></label>
    <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
    </p>
    <p>
    <label for="button"></label>
    <input type="submit" name="button" id="button" value="Submit" />
    </p>
    <p class="required"><span class="astric">*</span> indicates required</p>
    </form>
    </div>

    Thanks for your help

  5. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    At the moment the $subject variable is not being set anywhere in your script. Change the following part of your script:

    PHP Code:
    $subject 'You have an inquiry from the website';

    $extraheaders "From: $email\n\r Email sent from: $email\n\r";

    if (! 
    mail($myemail$subject$comments$extraheaders))
    echo 
    "Mail did not send for some reason."

  6. #6
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Wow! Thanks. That worked

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •