Home >>Advance PHP Tutorial >PHP Mail Function

PHP Mail Function



Sending Email using Php (Text mail Only

Most Popular Intern-ate service Now a days is Email. Thousands of Emails send and received each day.

The PHP Sending Email Tutorial goal's is to demonstrate how to send email.

Sometimes Sending Email by you contains Only Text message, sometimes it contains Some HTML Scripts and sometimes You want to send your mail some message with some attachments.

Sending a Simple Text Email

At First, lets start with Sending a Simple Text Email. The Php mail( ) function is used to send Emails in PHP. Inside mail( ) function you can pass three Basic and one optional Parameters.

Three Basic Parameters : The email address to send(Receiver email), Subject of mail, Content/message of the mail.

Optional Parameters: additional headers you want to include(headers and sender mail)

PHP Script

<?php
extract($_POST);
if(isset($sendmail))
{
	
    $subject ="Mail Function in PHP";
	$from="info@phptpoint.com";
	$message =$name." ".$mobile." ".$query;
    $headers = "From:".$from;
    mail($email,$subject,$message,$headers);
  
	echo "<h3 align='center'>Mail Sent Successfully</h3>";
}	
 
?>

HTML Form(enter your personal information which info u want to send)

<html>
<head>
	<title>Mail function in php - Phptpoint</title>
</head>
<body>
<form method="post">
 <table align="center" border="1">
	<Tr>
	<th>Enter Your name</th>
	<td><input type="text" name="name"/></td>
	</tr>
	<tr>
		<th>Enter Your mobile</th>
		<td><input type="text" name="mobile"/></td>
	</tr>	
	<tr>
		<th>Enter Your email</th>
		<td><input type="email" name="email"/></td>
	</tr>
	
	<tr>
		<th>Enter Your Query</th>
		<td><textarea name="query"></textarea></td>
	</tr>
		
	
	<tr>
		<td align="center" colspan="2">
		<input type="submit" value="Send Mail" name="sendmail"/>
		
	</tr>
	</table>	
</form>
</body>
</html>

In above example , a mail is sent to info@gmail.com which is receiver address and mail is sent by phptpoint. subject,messages and headers are also given.