Hello,

I'm pretty new to PHP and have set up a PHP email form that users can enter into my web site. It works pretty good, but I would like to set it up so that the email sent to my inbox has high priority so that I notice it.

I go through Godaddy.

Here's part of my first code:

<BODY>
<?php
$ip = $_POST['ip']; 
$httpref = $_POST['httpref']; 
$httpagent = $_POST['httpagent']; 
$visitor = $_POST['visitor']; 
$visitormail = $_POST['visitormail']; 
$notes = $_POST['notes'];
$todayis = date("l, F j, Y, g:i a") ;
$subject = "An Email from your web site";
$notes = stripcslashes($notes); 
$message = "Sent: \n $todayis \n\n
From: \n
$visitor ($visitormail) \n\n
Message:
$notes \n\n\n
Browser Information: $httpagent \n
Additional Information: IP = $ip \n
";
$from = "From: $visitormail\r\n";
mail("me@nono.com", $subject, $message, $from);
?>

and it take the user input from this page:

<FORM METHOD="POST" ACTION="thankyou.php" onSubmit="return checkIt(this);">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

The code works perfectly fine, but when I start to put $header functions in there with priority settings, it doesn't work??

Any help would be appreciated.

jj

    1. When posting PHP code, please use the board's [PHP][/PHP] bbcode tags - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your post now and add these bbcode tags to help others in reading/analyzing your code.

    2. You shouldn't put the IP/HTTP information in hidden form fields - this allows them to be manipulated into whatever the user wants them to be. Instead, just use the server variables.

    3. I don't know what you mean by $header functions... at present, the place you'd add extra headers would be in the $from variable.

      What I mean by the $header function is what I've found on a number of web sites such as:

      $headers  = "MIME-Version: 1.0\n";
         $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
         $headers .= "X-Priority: 3\n";
         $headers .= "X-MSMail-Priority: Normal\n";
         $headers .= "X-Mailer: php\n";
         $headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";
         return mail($toaddress, $subject, $message, $headers);
      

      I've tried a variety of settings, but can't get it to work in my Godaddy webmail application.

      Also, I'm not sure what you mean by:

      1. You shouldn't put the IP/HTTP information in hidden form fields - this allows them to be manipulated into whatever the user wants them to be. Instead, just use the server variables.

      How do I do that?

      Thanks,
      jj

        Right, you can add additional headers in the 4th parameter of mail(). I was just saying that in your previous code, you didn't call the variable $headers but rather $from, and I didn't know if you thought that the 4th parameter was simply reserved for the "from" address.

        jjbarnone wrote:

        How do I do that?

        The same way you retrieved them when you created the form. Just move that part into the second script that sends the mail, and get rid of the hidden form fields.

          Thanks for getting back to me, but I am very confused. I've never coded at all in PHP and am a little lost right now, but can figure things out pretty quickly. Here's the base code that I found on the Internet and that I'm working with, I've rewritten them to be a little more customized for my needs there are 2 files:

          The first one is named support.php

          <html>
          <head>
          <title>Your Site Contact Us Form</title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>
          
          <body>
          <p align="center"><font color="#000000">Please use this form to contact us</font></p>
          <p align="center"><font color="#000000">We value your questions and comments and 
            will reply to you as soon as we can.</font></p>
          <p>&nbsp;</p>
          <table align="center" cellpadding="5" cellspacing="5">
            <tr> 
              <td width="43"><div align="center"></div></td>
              <td width="425">
          
          <form method="post" action="sendeail.php"  onSubmit="return checkIt(this);">
          
          <?php
          $ipi = getenv("REMOTE_ADDR");
          $httprefi = getenv ("HTTP_REFERER");
          $httpagenti = getenv ("HTTP_USER_AGENT");
          ?>
          
              <p>
                <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
                <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
                <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
                Your Name: <br />
                <input type="text" name="visitor" size="35" id="name"/>
                <br />
                Your Email:<br />
                <input type="text" name="visitormail" size="35" id="email"/>
                <br />
                <br />
                <br />
                Subject:<br />
                <!-- edit, add and delete these options as required -->
                <select name="attn" size="1">
                  <option value=" YourSite.com : General Support ">General Support </option>
                  <option value=" YourSite.com : Pre-Sales Questions ">Pre-Sales Questions 
                  </option>
                  <option value=" YourSite.com : Billing ">Billing </option>
                  <option value=" YourSite.com : Technical Support ">Technical Support 
                  </option>
                  <option value=" YourSite.com : Suggestions ">Suggestions </option>
                  <option value=" YourSite.com : Other ">Other </option>
                </select>
                <br />
                <br />
                Mail Message: <br />
                <textarea name="notes" rows="4" cols="40" id="message"></textarea>
                <br />
                <input type="submit" value="Send Mail" id="message"/>
              </p>
              <br />
              </p>
            </form></td>
            </tr>
          </table>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          
          

          and then the second one is named sendeail.php

          
          <html>
          <head>
          <title>Thanks for contacting us</title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>
          
          <body>
          <!-- Reminder: Add the link for the 'next  or index page' (at the bottom) -->
          <!-- Reminder: Change 'YourEmail@YourSite.com' below to Your real email -->
          <?php
          
          $ip = $_POST['ip']; 
          $httpref = $_POST['httpref']; 
          $httpagent = $_POST['httpagent']; 
          $visitor = $_POST['visitor']; 
          $visitormail = $_POST['visitormail']; 
          $notes = $_POST['notes'];
          $attn = $_POST['attn'];
          
          
          
          
          $todayis = date("l, F j, Y, g:i a") ;
          
          $attn = $attn ; 
          $subject = $attn; 
          
          $notes = stripcslashes($notes); 
          
          $message = " $todayis [EST] \n
          Attention: $attn \n
          Message: $notes \n 
          From: $visitor ($visitormail)\n
          Additional Info : IP = $ip \n
          Browser Info: $httpagent \n
          Referral : $httpref \n
          ";
          
          $from = "From: $visitormail\r\n";
          
          
          mail("YourEmail@YourSite.com", $subject, $message, $from);
          
          ?>
          <p>&nbsp;</p>
          <p align="center"> <font color="#000000"><strong><img src="mail_send.jpg" width="48" height="48" align="absmiddle"> 
            &nbsp; Date : <?php echo $todayis ?> CST</strong></font></p>
          <p align="center"><font color="#000000"><br />
            <strong>Thank You : <?php echo $visitor ?>, <?php echo $visitormail ?></strong></font></p>
          <p align="center"><strong><font color="#000000"><br />
            Subject : <?php echo $attn ?> </font></strong></p>
          <p align="center"><strong><font color="#000000"><br />
            Message :<br />
            <?php $notesout = str_replace("\r", "<br/>", $notes); 
          echo $notesout; ?>
            </font></strong></p>
          <p align="center"><strong><font color="#000000"><br />
            IP : <?php echo $ip ?> </font></strong></p>
          <p align="center">&nbsp;</p>
          <p align="center"><font color="#013398"><strong><font color="#FF6633">We will 
            reply to you as soon as we can.</font></strong></font><font color="#000000"><br />
            </font><br />
          <p>&nbsp;</p>
          
          

          Thanks,
          jj

            If your question is "How Do I Set Email Priority" try this to send out a plain text email with highest priority setting:

            <?php
            
            $xPriority = 1;
            $xMSPriority = "Highest";
            $to = "someone@somewhere.com";
            $subject = "Test Email";
            $message = "This is an email to test out the priority setting";
            $headers = "From: foobar@wherever.com\r\nReply-To: foobar@wherever.com";
            $headers .= "MIME-Version: 1.0\n";
            $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
            $headers .= "X-Priority: $xPriority ($xMSPriority)\n";
            $headers .= "X-MSMail-Priority: $xMSPriority\n";
            if (!mail($to, $subject, $message, $headers))
               die("Could not send email");
            echo "Email sent.";
            ?>
            

            To change priorities:

            X-Priority strings:
            1 (Highest)
            2 (High)
            3 (Normal)
            4 (Low)
            5 (Lowest)

            X-MSMail-Priority strings:
            Highest
            High
            Normal
            Low
            Lowest

            On receipt, using MS Outlook and Thunderbird, I see the priority setting.

              Thanks to both of you for your input. It's working now. I was able to set the priority and get the IP/HTTP information from the server variables - rather than from the hidden form fields.

              So far I like PHP much better than ASP. It seems more forgiving considering that as I was testing this out, most of the emails still went through even if some errors were present - where in ASP I'd get massive errors and the whole thing would seem to blow up!

              Thank you again.

                Don't forget to mark this thread resolved (if it is).

                  Write a Reply...