If you are working on a website in which you have to send mail, that too automatically then how can you send.

Suppose you have created a portal in which you have to send certificate or user details to the mail of the agent, then you can send it to his mail automatically from the system through php script, like user details will be created or like someone clicks on open or else If something opens then its.

How can we send you normal mail and professional mail, in normal mail you can only send anything in text, but you want to send a professional mail whenever someone opens that mail, it should give a little professional look to it. For this, you can use HTML, CSS in it, so that the mail is very beautiful.

If you have Hostinger hpanel then you will not need any kind of library but if you have hosting or cpanel of any other company then you have to implement php mailer library only after that the below script will work

Send email in php code

To send a normal mail, you can use the code given below, how to set-up is given below.

Step 1:- First of all you have to create file named mailer.php in File Manager.

Step 2:- Then you have to open the mailer.php file, in it you have to enter the code given below.

<?php
$headers  .= 'From: help@domain.in' . "\r\n";
$headers .= 'Reply-To: help@domain.in' . "\r\n";
$headers .= 'Return-Path: help@domain.in';

if(mail('yourmail@gmail.com', 'My Subject Mail Send', 'Php Mail Successfully received.......', $headers)){
echo "Mail Sent.";
}else{
echo "Mail Not Sent.";
}
?>

As soon as you run the above code, you will receive an email on your mail.

 

 

PHP Script to Send Mail

If you want to send mail with HTML with CSS, then follow the steps given below for how to do it.

Step 1:- First of all you have to create file named mailer.php in File Manager.

Step 2:- Then you have to open the mailer.php file, in it you have to enter the code given below.

<?php

                $subject = "How to send html table in email body in PHP";
                $message = "<table width='980' border='1' style='border-collapse:collapse'>
<tbody><tr><td align='center' style='background:#b9dcff'><h1><span class='il'>Password</span> <span class='il'>reset</span> verification OTP</h1></td><td width='100' height='80' align='right'><img></td></tr>
<tr><td colspan='2'><br><b>Dear User,</b><br><br>Your verification OTP is <b>$code</b>. This OTP is valid for 15 min only.<br><br><br><br><br>This is a system generated mail.<br>
Please don't reply to this mail.<br><br><br><br><br>
Thanks &amp; Regards,<br>
<br>
</td></tr>
 <tr>
        <td align='center' colspan='2'>Please note if you are not the intended recipient of this message, please be aware that you are not authorized in any which way whatsoever to read, forward, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, we would request you to please notify the sender immediately by return e-mail and delete it from your computer. This e-mail message including attachment(s), if any, is believed to be free of any virus and Center is not responsible for any loss or damage arising in any way from its use. <br></td>
      </tr>
</tbody></table>". "\r\n";
$headers .='MINE-Version: 1.0'."\r\n";

$headers .='Content-type: text/html; charset=iso-8859-1'."\r\n";
$sender = 'From: help@domain.in'; 
$headers .= 'From:' . $sender. "\r\n";                
$headers .= 'Reply-To: help@domain.in' . "\r\n";
$headers .= 'Return-Path: help@domain.in';

if(mail('yourmail@gmail.com', $subject, $message, $headers)){
echo "Mail Sent.";
}else{
echo "fail";
}
?>

Step 3:- As you run by entering the above mentioned code, then you will receive the email immediately on the mail,

Preview will be shown to you on mail as you would have done HTML and CSS

Leave a Reply

Your email address will not be published. Required fields are marked *