Skip to content Skip to sidebar Skip to footer

HTML Contact Form Send Mail Through PHP

I have this code for a contact form in html:

Solution 1:

First of all, you should try to look for answers before you post questions, this is pretty much what the first result of googling "php send mail" will show you:

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
    //send email
    $from = $_REQUEST['author'] ;
    $to = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['msg'] ;
    mail($to, $subject, $message, "From:" . $from);

    // the mail was sent
    echo "Thank you for using our mail form";
}
else {
    //if "email" is not filled out, display the form
    //just close php and copy the code for your form
?>
- paste your html form here -
<?php
}
?>

The second thing is, I don't know what do you want to do with your author field. I suspect you have never sent an email with you having to enter who you are in any input field. The client kind of does that for you. So, with that in mind, I just left author at the bottom of the message.

This all providing you have a working email system set up in php.ini configuration settings.


Solution 2:

Here you go bud this will work with your form you posted above if you have questions let me know.

<?php

/* Subject and email variables */

$emailsSubject = 'This is where you type what you subject will show up as';
$webMaster  = 'youremail@gmail.com';


/* Gathering Data Variables - Whats in the form */

$name = $_POST ['name'];
$email = $_POST ['email'];
$subject = $_POST ['subject'];
$msg = $_POST['msg'];


/*Security*/




/* What You Want To See In The Email Place Inbetween $body = <<<EOD  and EOD; */    
$body = <<<EOD

<strong>Client:</strong> $name
<br />
<br />
<strong>Email:</strong> $email
<br />
<br />
<strong>Subject:</strong> $subject
<br />
<br />
______________________________________________
<br />
<br />
$msg

EOD;

/* Headers is a tag containing the users email and how you want it to display in your email */

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

/* This is what sends the email */
$success = mail($webMaster, $emailsSubject, $body, $headers);

/* Results Rendered as Html */
echo file_get_contents("http://yourdomain.com/after-message-sent/");

?>

For the "echo file_get_contents" you can create a page that you want your client to see after that tells them there message was sent. If you want it plain Jane then just echo Your message was sent. Hope this helps.


Post a Comment for "HTML Contact Form Send Mail Through PHP"