Saturday, July 18, 2015

anil

How to send mail in php




Step 1:- Create a html form to take input from user as follow:-

#INDEX.PHP
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <div style="width:600px; margin:0 auto;">
        <form action="mail.php" method="get">
            <table>
                <tr>
                    <td>Customer Name </td>
                    <td>
                        <input type="text" id="CustName" name="CustName" required />
                    </td>
                </tr>
                <tr>
                    <td>Customer Mail ID </td>
                    <td>
                        <input type="text" id="toMailID" name="toMailID" required/>
                    </td>
                    </tr>
                    <tr>
                    <td>Attach file</td>
                    <td>
                        <input type="file" name="upload" id="upload" />
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <input type="submit" value="Submit" />                   
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
Step 2:- When you run it on browser it will look like this:-

Step 3:- Now create mail.php page as follow:-

#MAIL.PHP
 <?php
$companyContactNo = 'your contact number';
$CustName = $_REQUEST['CustName'];
$companyName = 'abc Infotech Pvt. Ltd.';
$companyEmailID = 'comapnay mail id';
$file = $_REQUEST['upload'];
$toMailID = $_REQUEST['toMailID'];
//declare our variables
$EMAIL = 'your mail id'; //Set ThiFrom Mail ID
//get todays date
$todayis = date("l, F j, Y, g:i a") ;
//set a title for the message
$subject = "Inquiry from vatikasovereignpark.com Minisite";
$attachment = $file;
//include attachment
$body ="--PHP-mixed-\r\n"."Content-Type: application/zip;
name=\.$attachment.\"\r\n"."Content-Transfer-Encoding:
base64\r\n"."Content-Disposition: attachment\r\n\r\n";
$body .= $attachment;
$body = "
<html>
<head>
</head>
<body>
      
        <div style = 'border-top:3px solid #22BCE5'>&nbsp;</div>
        <p>Dear $CustName </p>
        <p>Thank you for Contacting $companyName. </p>
        <p>We have started working on your computer problems reported to our team. We hope to fix your computer issues at earliest and will update you shortly.</p>
        <p>When you call, please have below information handy so that we can expedite your request.</p>
        <br/>
        <b>Regards</b><br/>
        <p>Hacxad Infotech Pvt. Ltd</p>
        <p>EmailID - $companyEmailID</p>
        <p>Contact No - $companyContactNo</p>
</body>
</html>";
$headers = 'From: '.$EMAIL.'' . "\r\n" .
    'Reply-To: '.$EMAIL.'' . "\r\n" .
    'Content-type: text/html; charset=utf-8' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

//put your email address here
$status = mail($toMailID, $subject, $body, $headers);
if($status){ echo "mail send ... OK";
             //header('Location:index.php');
              }
else{ echo "mail send ... ERROR!"; }
?>
Step 3:- Now input your correct mail it or name into input box and submit it.

Step 4:- If  mail has sent, you will get message:-
        Mail send... OK
Step 5:- If mail is not send on your mail id due to any error, you will get message:-
mail send ...ERROR!
So using above process you can send e-mail on any type of mail id.
 


About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a huge information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :

2 comments

Write comments
Unknown
AUTHOR
February 7, 2016 at 8:58 PM delete

Plz give me a mail server project in php

Reply
avatar
anil
AUTHOR
February 7, 2016 at 11:31 PM delete

have you tried the process of mail sending as I posted????

Reply
avatar

Note: Only a member of this blog may post a comment.