after hosting is done for your website.
you can send email by using the below code of mail function in PHP
<?php
if(isset($_POST['submit']))
{
$errors = '';
if(empty($_POST['name']) ||
empty($_POST['toemail'])||
empty($_POST['subject']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$myemail = $_POST['toemail'];//<-----Put Your email address here.
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "<br> Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n\n Subject: $subject \n\n Email: $email_address \n\n Message \n\n $message";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
echo "<center><p style=\"color:Green\"> Thank you !!! We will come to you shortly</p></center>";
}
else
{
echo "<center><p style=\"color:Red\">".$errors."</p></center>";
}
}
?>
<html>
<head>
<title>Send email using php</title>
</head>
<body>
<form id="form" name="form" method="post" action="">
<center>
<table>
<tr><td>Enter emailid for To : </td><td><input type="text" name="toemail" /></tr>
<tr><td>Enter your Name : </td><td><input type="text" name="name" /></tr>
<tr><td>Enter your Email : </td><td><input type="text" name="email" /></tr>
<tr><td>Enter your Subject : </td><td><input type="text" name="subject" /></tr>
<tr><td>Enter your Message : </td><td><input type="text" name="message" /></tr>
<tr><td></td><td>
<input type="submit" name="submit" value="submit" /></tr>
</table>
</center>
</form>
</body>
</html>
you can send email by using the below code of mail function in PHP
<?php
if(isset($_POST['submit']))
{
$errors = '';
if(empty($_POST['name']) ||
empty($_POST['toemail'])||
empty($_POST['subject']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$myemail = $_POST['toemail'];//<-----Put Your email address here.
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "<br> Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n\n Subject: $subject \n\n Email: $email_address \n\n Message \n\n $message";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
echo "<center><p style=\"color:Green\"> Thank you !!! We will come to you shortly</p></center>";
}
else
{
echo "<center><p style=\"color:Red\">".$errors."</p></center>";
}
}
?>
<html>
<head>
<title>Send email using php</title>
</head>
<body>
<form id="form" name="form" method="post" action="">
<center>
<table>
<tr><td>Enter emailid for To : </td><td><input type="text" name="toemail" /></tr>
<tr><td>Enter your Name : </td><td><input type="text" name="name" /></tr>
<tr><td>Enter your Email : </td><td><input type="text" name="email" /></tr>
<tr><td>Enter your Subject : </td><td><input type="text" name="subject" /></tr>
<tr><td>Enter your Message : </td><td><input type="text" name="message" /></tr>
<tr><td></td><td>
<input type="submit" name="submit" value="submit" /></tr>
</table>
</center>
</form>
</body>
</html>
No comments:
Post a Comment