-2

So I'm trying to create an email form for my Contact Us Page. my problem is i dont have any idea on how does this email form i have this code for my Form As Shown Below:

<form method = "post" action = "contactus.php" enctype="multipart/form-data">
<div class = "emailform">
    <input type = "text" placeholder = "Name" name = "name" style="width:450px; padding:5px;" required><br>
    <input type = "text" placeholder = "Email" name = "email" style="width:450px; padding:5px;" required><br>
    <textarea name = "message" placeholder = "Message" style = "width:450px; padding: 5px; height: 155px;" required></textarea><br>
    <button type = "submit" name = "send">Send</button>
</div>
</form> 

it will be really helpful if someone answer by the way I'm only using notepad++ for editing my codes. and im also a newbie :)

Thank you in advance

2 Answers2

0

try this in your contactus.php page.

<?php


$to = "recieveraddress@mail.com";
$subject = "Your subject";
$txt = $_POST['message'];
$headers = "From: ".$_POST['email'];

mail($to,$subject,$txt,$headers);
?> 
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
0

Add below code in your "contactus.php" file.And replace "your@email.com" with your email address.Please put "contactus.php" in the same directory where your form file is placed.

<?php
function clean($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
if(isset($_POST['name'],$_POST['email'],$_POST['message']) && $_POST['name'] != '' && $_POST['email'] != '' && $_POST['message'] != '') {
    foreach($_POST as $key = > $value)
        $_POST[$key] = clean($value);

    $to = 'your@email.com';
    $from = $_POST['email'];
    $subject = 'Customer support needed';
    $message = 'Name='.$_POST['name'].'  Message='.$_POST['message']; 


    // Sending email
    if(mail($to, $subject, $message)){
        echo 'Your mail has been sent successfully.';
    } else{
        echo 'Unable to send email. Please try again.';
    }
}
?>
Dinesh Belkare
  • 639
  • 8
  • 24
  • Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\Villa d El-lita\contactus.php on line 83 – Melvin Pascual Oct 19 '15 at 10:12
  • i think the code works i jst need to figure out how to fix this error – Melvin Pascual Oct 19 '15 at 10:13
  • Yes,This is working code.You just need to look at your server configuration.And if done, please accept this answer. – Dinesh Belkare Oct 20 '15 at 09:02