How to Create Contact Us Form In WordPress Without Pluggins?
How to receive email on Direct on your Email inbox
Here is Step by Step Tutorial and Source Code Free to Use.
Step 1
Open File Manager in Your Website (if You have not Installed File Manager in Your Website, go to Plugins to Download and install File Manager In WordPress, You can Also Explore WordPress Files By Your Hosting Provider Control Pannel)
Create a New Folder and also Create a New PHP File inside New Folder.
Sample :- File Name : "Conatct.php", Folder Name "contact", Location : "public_html/conatct/contact.php"
(Note :- This is sample only. You can use diffrent PHP File Name and Folder Name and File locations.)
Step 2
Copy this PHP Code and Paste it to inside PHP File by Edit File Right Clicking on PHP File, Then Edit By Highlighted Text Inside Code Then Save It.
<?php
$conPage='https://youwebsite.com/contact/'; //Add Your website contact page url,
$domNam=str_replace('www.','',$_SERVER['SERVER_NAME']);
$refEr=$_SERVER['HTTP_REFERER'];
if($conPage==$refEr){ // validate get only data from your mention website url;
$parameter = $_SERVER['QUERY_STRING'];
$idArray = explode('&',$parameter);
?><?php
$to = 'your@email.com'; //Change to Your Email Address, Where You Receive Contact Emails;
$subject = "Contact - $domNam";
$from = 'your@website.com'; //Change to Your Source Email Address, receiving Emails From This Email Address;
$headers = 'MIME-Version: 1.0' . "\r\n"; // To send HTML mail, the Content-type header must be set
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= "From: '$domNam' ".$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Custome html form fiels visible into your email
$message = '<table width="690" cellspacing="0" cellpadding="0" border="0" align="center"><tbody><tr><td bgcolor="#F0F0F0">
<table width="640" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody><tr><td height="16"></td></tr><tr>
<td style="font-family: arial,Arial,sans-serif;text-transform:uppercase;font-size: 25px;">
<b>'.str_replace('www.','',$_SERVER['SERVER_NAME']).'</b></td></tr><tr><td height="16"></td></tr>'; ?>
<?php
foreach ($idArray as $index => $avPair) { list($ignore, $value) = explode("=", $avPair); $id[$index] = $value; $message .='
<tr>
<td align="left" bgcolor="#FFFFFF"><div style="border-style:solid;border-width:1px;border-color:#cccccc; margin-bottom: -1px;">
<table width="625" cellspacing="0" cellpadding="0" border="0" align="center"><tbody><tr><td height="15" colspan="3"></td>
</tr><tr><td width="15"></td><td width="600"><div style="font-family:arial,Arial,sans-serif"><table cellspacing="0" cellpadding="0" border="0">
<tbody><tr><td width="100" style="color:#787878;text-transform: capitalize;font-size:13px;"><b>'. str_replace('-',' ',$ignore).': </b>
</td><td width="15"></td><td><div style="color:#929292;line-height:24px;font-size: 14px;">'. urldecode(str_replace('+',' ',$id[$index])).'
</div></td></tr></tbody></table></div></td><td width="15"></td></tr><tr><td height="15" colspan="3"></td></tr></tbody></table>
</div></td></tr>'; } ?><?php
$message .= '<tr><td height="16"></td></tr><tr><td align="left"><table cellspacing="0" cellpadding="0" border="0" align="center">
<tbody><tr><td width="498"><div style="font-family:arial,Arial,sans-serif;font-size:11px;color:#999999;line-height:13px;text-align: center;"> © '.date('Y').' Developed by <a style="color: #999999;text-decoration: none;" href="https://shrimuktsarsahib.com/" target="_blank">PB INDIA</a></div>
</td></tr></tbody></table></td></tr><tr><td height="22"></td></tr></tbody></table></td></tr></tbody></table>';
if(mail($to, $subject, $message, $headers)){
//echo '<h2 style="font-family: system-ui;"><b>Your Message was Sent Successfully</h2>';
echo"<br>";
echo "<p style='text-align: center;font-family: system-ui;'>Your Message was Sent Successfully</p>";
header( 'refresh:1;url='.$_SERVER["HTTP_REFERER"] );
}
else { echo 'Error Unable to send message. Please try again.'; header( 'refresh:1;url='.$_SERVER["HTTP_REFERER"] );
}
?><?php } else {echo "<p>Sorry, You are not allowed to access this page!</p>"; exit(); } ?>
Step 3
Create a Contact Page in WordPress Website. Edit this Page add “Custom html” by Searching html in Post Creation Tools
Copy This Code and Paste it to your New Contact Page with Custome HTML Blog
<!DOCTYPE html>
<html lang="en">
<body>
<form action="https://yourwebsite.com/folder/contact.php" method="get"> //change php file link here
<p><label><span><input type="text" name="your-name" value="" size="40" required="required"
placeholder="Name"></span></label></p>
<p><label><span><input type="text" name="your-email" value="" size="40" required="required"
placeholder="Enter Your Email"></span></label></p>
<p><label><span><input type="text" name="your-message" aria-invalid="false" size="40"
style="border: radius 50px" placeholder="Enter Message Here"></label></p>
<p><button class="btn" type="submit">Submit</button></p>
</form>
</body>
</html>
Now You Can Check Your Contact Form was Successfully Work.
if facing any problem please comment only for contact form related comment. do not type other promotional comment here.
Thanks For Visite ❤