Tuesday 2 August 2016

how to send email with html formate in php wordpress

$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Booking Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>First Name:</strong> </td><td>" . strip_tags($_POST['firstname']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Last Name:</strong> </td><td>" . strip_tags($_POST['lastname']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['address']) . "</td></tr>";
$message .= "<tr><td><strong>city:</strong> </td><td>" . strip_tags($_POST['city']) . "</td></tr>";
$message .= "<tr><td><strong>state:</strong> </td><td>" . $_POST['state'] . "</td></tr>";
$message .= "<tr><td><strong>Zip Code:</strong> </td><td>" . htmlentities($_POST['zipcode']) . "</td></tr>";
$message .= "<tr><td><strong>Comming Date:</strong> </td><td>" . htmlentities($_POST['choose_date']) . "</td></tr>";
$message .= "<tr><td><strong><h3 style='background: #eee;'>Booking Add Successfull</h3></strong> </td><td>";
$message .= "</table>";
$message .= "</body></html>";

//  MAKE SURE THE "FROM" EMAIL ADDRESS DOESN'T HAVE ANY NASTY STUFF IN IT

$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
         if (preg_match($pattern, trim(strip_tags($_POST['email'])))) {
            $cleanedFrom = trim(strip_tags($_POST['email']));
          } else {
             return "The email address you entered was invalid. Please try again!";
           }

            //   CHANGE THE BELOW VARIABLES TO YOUR NEEDS
           
$to = "you emai id ";

$subject = 'subject';

$headers = "From: " . $cleanedFrom . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

            if (wp_mail($to, $subject, $message, $headers)) {
              echo 'email send successfull.';
            } else {
              echo 'There was a problem sending the email.';
            }

NOTE : if You code is use in php only use mail($to, $subject, $message, $headers) function.
  

No comments:

Post a Comment