alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

How to Send Text and HTML Emails in PHP- PHP Email Code Example

How to Send Text and HTML Emails in PHP- PHP Email Code Example

PHP Send Emails in HTML Formate

(How to Send Text and HTML Emails in PHP- PHP Email Code Example.using this example of code you can send easily mail in well formatted of html table.just you need to copy the entire code and paste inside your file)

Mail Example code:-

<form action="#" class="contact-form">
                            <div class="row m-0">
                                <div class="col-12 p-0">
                                    <input type="text" name="name" placeholder="Fullname" class="form-control">
                                </div>
                                <div class="col-12 p-0">
                                    <input type="text" name="number" placeholder="Your Number" class="form-control">
                                </div>
                                <div class="col-12 p-0">
                                    <input type="email" name="email" placeholder="Email" class="form-control">
                                </div>
                                <div class="col-12 p-0" >
                                    <div class="form-control">
                                    <label for="cars"> <b>Choose Options:-</b></label>
                                      <select name="cars" id="cars" required="">
                                        <option value="" hidden><b> PURPOSE </b></option>
                                        <option value="Partnership">Partnership</option>
                                        <option value="Services">Services</option>
                                        <option value="Pricing">Pricing</option>
                                        <option value="For business">For business</option>
                                        <option value="Other">Other</option>
                                        
                                      </select>
                                      </div>
                                </div>
                            
                                <div class="col-12 p-0">
                                    <textarea name="message" id="" rows="6" class="form-control" placeholder="Message"></textarea>
                                </div>
                                <div class="col-12 p-0 text-right">
                                    <button type="submit" name="sendInquiry" class="btn btn-primary">Submit</button>
                                </div>
                            </div>
                        </form>

<?php
                            if(isset($_REQUEST["sendInquiry"]))
                            {
                               $to = 'info@trimwebsolutions.com'; 
                                $from = $_REQUEST["email"]; 
                                $fromName = $_REQUEST["name"]; 
                                $mobile=$_REQUEST["number"]; 
                                $purpose=$_REQUEST["cars"];
                                $msg=$_REQUEST["message"];
                                $subject = "Your Website Enquiry ".Date("D-m-Y"); 
                                 
                                $htmlContent = ' 
                                    <html> 
                                    <head> 
                                        <title>Welcome to Trimwebsolutions</title> 
                                    </head> 
                                    <body> 
                                        <h1>Thanks you for joining with us!</h1> 
                                        <table cellspacing="0" style="border: 2px dashed #FB4314; width: 100%;"> 
                                            <tr> 
                                                <th>Name:</th><td>'.$fromName.'</td> 
                                            </tr> 
                                            <tr style="background-color: #e0e0e0;"> 
                                                <th>Email:</th><td>'.$from.'</td> 
                                            </tr>
                                            <tr style="background-color: #e0e0e0;"> 
                                                <th>Mobile:</th><td>'.$mobile.'</td> 
                                            </tr>
                                            <tr style="background-color: #e0e0e0;"> 
                                                <th>Purpose:</th><td>'.$purpose.'</td> 
                                            </tr>
                                            <tr style="background-color: #e0e0e0;"> 
                                                <th>Message:</th><td>'.$msg.'</td> 
                                            </tr>
                                            
                                            <tr> 
                                                <th>Website:</th><td><a href="https://www.trimwebsolutions.com">www.trimwebsolutions.com</a></td> 
                                            </tr> 
                                        </table> 
                                    </body> 
                                    </html>'; 
                                 
                                // Set content-type header for sending HTML email 
                                $headers = "MIME-Version: 1.0" . "\r\n"; 
                                $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
                                 
                                // Additional headers 
                                $headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n"; 
                                $headers .= 'Cc: info@trimwebsolutions.com' . "\r\n"; 
                                $headers .= 'Bcc: admin@trimwebsolutions.com' . "\r\n"; 
                                 
                                // Send email 
                                if(mail($to, $subject, $htmlContent, $headers)){ 
                                    echo 'Email has sent successfully.'; 
                                }else{ 
                                   echo '<font color="green">Email sending failed.</font>'; 
                                }
                            }
                        ?>


851 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online