0

I have this code for a contact form in html:

 <form method=post action=sendmail.php>
    <div class=one_third>
      <label>Name</label>
      <input type=text name=author value id=name />
    </div>
    <div class=one_third>
      <label>Email</label>
      <input type=text name=email value id=email />
    </div>
    <div class="one_third last">
      <label>Subject</label>
      <input type=text name=subject value id=subject />
    </div>
    <div class=full_width>
      <label>Your Message</label>
      <textarea name=msg id=msg></textarea>
    </div>
    <input type=submit name=submit value=Submit />
  </form>

I would likes to know if you can provide me with a php code, to go inside "sendmail.php" that will actually send the email.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
user2880171
  • 1
  • 1
  • 1

2 Answers2

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.

rockerist
  • 21
  • 1
  • 1
  • 5
  • I mean an external code to be executed when submit button is clicked, that will check all fields on a different html file and then send the email. – user2880171 Oct 20 '13 at 17:17
  • Sorry, still not getting it. Which external code, how do you plan to invoke it with a submit button and what other files do you need? If you want to check the fields if they are empty, you can cascade the >>if (isset<< part for each of the fields. If you want more (checking, security or whatever), you should really take some time to find mailing scripts on the internet, there are quite a lot of them available, or at least pay someone to write the code you need ;) – rockerist Oct 20 '13 at 18:25
0

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.

javacoder101
  • 343
  • 2
  • 6