Tutorial Simple PHP Contact Form

PhucedMODZ

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Points
463
Hello CCM!

Today I’m Going To Show A Quick Tutotial On How To Make A Simple PHP Contact Form!

So Let’s Get Into It.

First You Will Need To Open A IDE Of Your Choice!

I Highly Recommend Sublime Or NotePad++


Once You Have Opened Your IDE Of Choice Create A File Called

contact.php

In That File Add The Following Code

HTML:
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Now Once You Have Done That, Save The File!


But Hold Up, Were Not Done Yet

Now You Need To Create Another File Called send.php

In That File Add The Following Code (Edit It To Your Needs & Add Your Email Address In The $to Part)

PHP:
<?php

// Contact subject
$subject ="$subject";

// Details
$message="$detail";

// Mail of sender
$mail_from="$customer_mail";

// From
$header="from: $name <$mail_from>";

// Enter your email address
$to ='[email protected]';
$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>

Now Save That File Aswell And Upload Them To Your Website / Server

Now Send A Test Message And Make Sure It All Works!

That’s All For This Quick Tutorial!

Thanks For Looking Guys, Hope You Have A Nice Day!

If You Need Any Help Feel Free To Contact Me!


PS. Sorry About The Formatting, I Wrote This On My Phone Using An App
 
Last edited:

Matt

Backend Web Developer
Messages
245
Points
603
Probably necro’ing an old thread but tables :mask: - Not very good for mobile optimisation, but alright code non-the-less

Tbh I would probably go with Materialize Premade tables (because their overall design is much sleeker) and incorporate your PHP to work with it.

Good thread non the less
 

PhucedMODZ

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Points
463
Probably necro’ing an old thread but tables :mask: - Not very good for mobile optimisation, but alright code non-the-less

Tbh I would probably go with Materialize Premade tables (because their overall design is much sleeker) and incorporate your PHP to work with it.

Good thread non the less
yeah lol, i wrote it on my phone :grinning: and i had a shitty iphone 5s (got iphone 8plus in grey now) so i can see what im doing properly,maybe i should re do it all on my pc, but thanks mate
 

PhucedMODZ

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Points
463
This put's emails in spam?! Or is it just me? Using the mail function to send confirmation emails out on
You do not have permission to view link Log in or register now.
and they end up in spam...
No, it’s just a contact form, say for instance you send a message / email to me it shows your email etc
 

Harry

Software Engineer
Premium Member
Messages
1,272
Points
748
No, it’s just a contact form, say for instance you send a message / email to me it shows your email etc
I know what it is... the mail function for me, sends those emails to the spam box...
 

PhucedMODZ

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Points
463
I know what it is... the mail function for me, sends those emails to the spam box...
Ahh right lol give me 10 mins, I’ll reply back to this with a different type of php mailer, if your using a vps like I am then install sendmail
 

Harry

Software Engineer
Premium Member
Messages
1,272
Points
748
Which should output it like this
I am using the PHP function 'mail()' in my script. Not on a VPS, but shared hosting...
Sending my emails to spam... Not a huge issue, I don't care, but bugs me a little.
 

PhucedMODZ

Trial Moderator
Staff member
Trial Moderator
Donator
Messages
181
Points
463
I am using the PHP function 'mail()' in my script. Not on a VPS, but shared hosting...
Sending my emails to spam... Not a huge issue, I don't care, but bugs me a little.

$to = $email;
$subject = 'Your Subject';
$message = 'Your Message';
$headers = 'From: [email protected]' . "\r\n";
mail($to, $subject, $message, $headers);



try that bro took it straight from my site
 
  • Like
Reactions: SCP

SCP

Moderator
Staff member
Donator
Messages
393
Points
423
I know what it is... the mail function for me, sends those emails to the spam box...
The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.

Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.

Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.

You do not have permission to view link Log in or register now.
 

Top