Sending emails using PHP is not a big deal. Using PHP mail function we can send emails easily. But sometimes we may need to send emails using high priority and urgent basis. For this, we need to add some extra PHP mail headers to the php script to send the email with high importance.

The types we can use either X-MSMail-Priority or X-Priority with the following values: 1 = High, 3 = Normal, 5 = Low

For example, if you like to use X-MSMail-Priority it will be - X-MSMail-Priority: High or if you like to use X-Priority then X-Priority: 1

So below is the piece of code which sends the email with high priority and urgent basis.

The types we can use either X-MSMail-Priority or X-Priority with the following values: 1 = High, 3 = Normal, 5 = Low

For example, if you like to use X-MSMail-Priority it will be - X-MSMail-Priority: High or if you like to use X-Priority then X-Priority: 1

So below is the piece of code which sends the email with high priority and urgent basis.

The Form - form.php

<html>
<head>
<title> PHP - Mail function for urgent and high priority </title>
<link href='style.css' rel='stylesheet' type='text/css'>
</head>
<body>
    <div class='contactForm'>
     <form action='process.php' method='post'>
        <h2>Please fill the form.</h2>
        <input type='text' name='name' placeholder='Name' required>
        <input type='email' name='email' placeholder='Email' required>
        <input type='text' name='phone' placeholder='Phone'>
        <textarea rows='3' name='message' placeholder='message'></textarea>
        <input type='submit' name='submit' value='Submit' class='btn'>
     </form>
    </div>
</body>
<html>

A little bit design will make our form look good. 

Style - style.css

.contactForm{
         border: 1px solid #ccc;
         max-width:410px;
         margin: auto;
         background: #ddd;
         padding: 10px;
 }
    .contactForm h2{
         color: #404040;
         text-shadow: 1px 1px #fff;
         font-size: 2em;
         text-align: center;
         border-bottom: 1px solid #999;
 }
    .contactForm input:not(.btn),
    .contactForm textarea{
         display: block;
         border:1px solid #ccc;
         width:100%;
         margin:5px 0px;
         padding:5px;
 }
    .contactForm input:focus, 
    .contactForm textarea:focus{
         font-style: italic;
         font-weight: bold;
 }
    .btn{
         background: #8BC34A;
         color: #FFF;
         padding: 5px 10px;
         border: 1px solid #7DAF42;
         box-shadow: 1px 1px #F1EBEB;
        border-radius: 2px;
 }
    .btn:hover{
        background: #4CAF50;
 }

This is how our basic form looks like

php-mail-function-for-urgent-and-high-priority

 Now the most important part is processing the form with the php script to send emails.

Form process - process.php

<?php 
$email_to='user@example.com'; // web admin address - emails sent to this address
$email_subject='New Enquiry'; // set email subject
$thankyou_page='thank-you.php'; // redirect users to thank you page after submitting the form
if(isset($_POST['submit']))
{
$name=$_POST['name']; // Name input by user in the form
$email=$_POST['email']; // Email input by user in the form
$message=$_POST['message']; // Message input by user in the form
$phone=$_POST['phone']; // Phone no. input by user in the form
 
// Creating the message for sending mail
 $msg="Message : 
 Name : ".$name."
 Email : ".$email."
 Phone no. : ".$phone."
 Message : ".$message;
 
 $headers="from: ".$email."\n". //creating headers
 "reply-to: ".$email."\n". //creating headers
 "X-Priority: 1\n". //headers for priority
 "Priority: Urgent\n". //headers for priority
 "Importance: high";
 mail($email_to,$email_subject,$msg,$headers); // sending the email
 
//Send the people to thank-you page once they submitted the form.
 echo '<script>javascript:location.href="'.$thankyou_page.'"</script>'; 
}
?> 

So the above code snippets will send the email on the urgent basis and high priority . … that’s all.