Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    47
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Email script not retrieving/passing variables

    I am having a problem getting my php email script to retrieve variables from the email form. The email sends properly, however, it is blank. I've used this same email script before with not problems so I don't know what is going on. Also, whenever the email arrives, it outputs twice, like this:
    Sender:
    Company:
    Sender:
    Company:

    PHP Code:
    <fieldset id="loginMenu">

    <form action="index.php" method="post">

        <fieldset id="formLeft">
        
        <select name="recipient">
    <option value="">Choose a recipient</option>
    <option value="recipient_1">Person One</option>
    <option value="recipient_2">Person Two</option>
    <option value="recipient_3">Person Three</option>
    </select>

            <label>Name</label>
            <input type="text" id="name" name="name" value="" />
            <label>Company</label>
            <input type="text" id="company" name="company" value="" />
            <label>Email</label>
            <input type="text" id="email" name="email" value="" />
        </fieldset>
        
        <fieldset id="formRight">
            <label>Message</label>
            <textarea id="comment" name="comment"></textarea>
            <input type="image" class="btn" value="Send Message" />
        </fieldset>
        
    </form>

      </fieldset>
      
      <?php
    if (isset($_POST['email'])) {
    $subject "Contact Form";
    $email $_REQUEST['email'] ;
    $comment $_REQUEST['comment'] ;
    $message "$message";
    $headers "From: $name";
    $recipients = array(

    'recipient_1' => 'email1@email.com',
    'recipient_2' => 'email2@email.com',
    'recipient_3' => 'email3@email.com'

    );

    $to $recipients[$_REQUEST['recipient']];
    mail($to$subject$message$headers) ;

    if(
    $sent)
    {print 
    "Your mail was sent successfully"; }
    else
    {print 
    "We encountered an error sending your mail"; }
    }
    ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Your message field is named "comment" but you are trying to send $message as the body text, which is blank. The code should look similar to this:
    PHP Code:
    $subject "Contact Form"
    $email $_REQUEST['email'] ; 
    $comment $_REQUEST['comment'] ; 
    $headers "From: $name"
    $recipients = array( 
        
    'recipient_1' => 'email1@email.com'
        
    'recipient_2' => 'email2@email.com'
        
    'recipient_3' => 'email3@email.com' 
    ); 

    $to $recipients[$_REQUEST['recipient']]; 
    mail($to$subject$comment$headers); 

  • Users who have thanked Inigoesdr for this post:

    mathruD (09-15-2011)

  • #3
    New Coder
    Join Date
    Apr 2011
    Posts
    47
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Your message field is named "comment" but you are trying to send $message as the body text, which is blank. The code should look similar to this:
    PHP Code:
    $subject "Contact Form"
    $email $_REQUEST['email'] ; 
    $comment $_REQUEST['comment'] ; 
    $headers "From: $name"
    $recipients = array( 
        
    'recipient_1' => 'email1@email.com'
        
    'recipient_2' => 'email2@email.com'
        
    'recipient_3' => 'email3@email.com' 
    ); 

    $to $recipients[$_REQUEST['recipient']]; 
    mail($to$subject$comment$headers); 
    thanks. that did work. i don't know how i overlooked that.

    however, there is still one slight problem. all of the info is sent just fine, but the header field isn't working properly. no matter what i put in the header field it is showing up as some default address from my hosting account.

    it's arriving as, "From: username@pass87.dizinc.com"

    what does this mean? or what am i doing improperly to cause this?

    thanks for the help so far.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    You may need to use the additional paramters parameter then with the -f option.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    mathruD (09-15-2011)

  • #5
    New Coder
    Join Date
    Apr 2011
    Posts
    47
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    You may need to use the additional paramters parameter then with the -f option.
    you are absolutely correct. the additional parameter seemed to fix it. it also appears that there is a specific way that the header has to be written (depending on the hosting provider) in order to display the properly. some ways work and others don't.


  •  

    Posting Permissions

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