Web Analytics Made Easy -
StatCounter Email script not retrieving/passing variables - CodingForum

Announcement

Collapse
No announcement yet.

Email script not retrieving/passing variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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' => '[email protected]',
    'recipient_2' => '[email protected]',
    'recipient_3' => '[email protected]'

    );

    $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
    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' => '[email protected]'
        
    'recipient_2' => '[email protected]'
        
    'recipient_3' => '[email protected]
    ); 

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

    Comment


    • #3
      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' => '[email protected]'
          
      'recipient_2' => '[email protected]'
          
      'recipient_3' => '[email protected]
      ); 

      $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: [email protected]"

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

      thanks for the help so far.

      Comment


      • #4
        You may need to use the additional paramters parameter then with the -f option.
        "Tango says double quotes with a single ( ' ) quote in the middle"
        '$Name says single quotes with a double ( " ) quote in the middle'
        "Tango says double quotes ( \" ) must escape a double quote"
        '$Name single quotes ( \' ) must escape a single quote'

        Comment


        • #5
          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.

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎