I am going to apologize off the bat for posting an email form question when there are sooooo many others... but honestly, i looked at them all before i wrote this.

I have a form that contains a place to type in 'name', 'subject', 'message', and 'email'. When ever the information is filled out and the send button is hit, I only receive the 'subject' and 'message' information.

Here is my code...

<?php

$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "myemail@gmail.com";
$msg = "$subject\n\n";
$msg = "$message\n\n";

mail($to, $subject, $msg, "From: My web site\nReply-To: $email\n");

header("location:bio.html");

?>

What am i missing to be able to receive all the information when i hit send?

Thank you sooo much in advance.
Gab

Recommended Answers

All 4 Replies

Member Avatar for langsor

Hi,

These are where you're getting the information passed in from your html form $_POST and $_POST, so since you have form-fields for name and email, you will want to also define those values in your PHP script as $_POST and $_POST and then use the values in your email sending script -- is this what you're asking?

So maybe something like this ...

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "myemail@gmail.com";
$msg = "$subject\n\n";
$msg = "$message\n\n";

mail ($to, $subject, $msg, "From: My web site\nReply-To: $email\n");

header("location:bio.html");

?>

You might also look at some of the discussions and examples on the main PHP website ... http://us2.php.net/function.mail

Good luck

Thank you for your quick reply.
I did what you suggested but i still got the same results. Just the subject and message showed up. I ended up playing around with my code some more and came up with this idea...

<?php

$subject = $_POST['subject'];
$message = $_POST['message'];
$email = $_POST['email'];
$name = $_POST['name'];
$to = "gabriellebess@gmail.com";
$msg = "$subject\n\n";
$msg = "$message\n\n";
$msg = "$email\n\n";
$msg = "$name\n\n";

mail($to, $subject, $msg, "From: My web site\nReply-To: $email\n");

header("location:bio.html");

?>

That time, the subject and name were emailed to me instead.

Looking at the site that you suggested to me, i feel as though i might need to use headers in order to get my commands across. The idea of headers is still a little confusing to me (im very new to php) could you possibly describe them in laymen's terms for me? perhaps then i could figure this whole thing out.

Thanks
Gab

Member Avatar for langsor

I don't really do much PHP email stuff, but this should work for you. The 'headers' are the From line and optionally some other info too.

<?php
// php mail plain-text email example
$recipient = "gabriellebess@gmail.com";
$subject = $_POST['subject'];

$name = $_POST['name'];
$email = $_POST['email'];
$body= $_POST['message'];

$message = "Name: ". $name ."\n\n";
$message .= "Email: ". $email ."\n\n";
$message .= "Body:\n\n ".  $body ."\n\n";

$headers = "From: ". $name ."<". $email .">\r\n";
$headers .= "Reply-To: ". $name ."<". $email .">\n\n";
$headers .= "X-Mailer: PHP-Mailer";

if ( mail( $recipient, $subject, $message, $headers ) {
  header("location:bio.html");
}
?>

Hope it helps

Thank you for your help. After a little modification of the code you sent me, it worked! Here is the code I used just in case some one else needs it...

<?php
   
      $recipient = "myemail@gmail.com";
   
      $subject = $_POST['subject'];
   
       
      $name = $_POST['name'];
   
      $email = $_POST['email'];
   
      $body= $_POST['message'];
   
      $message = "Name: ". $name ."\n\n";
  
      $message .= "Email: ". $email ."\n\n";
  
      $message .= "Body: ". $body ."\n\n";
  
 
      mail ($recipient, $subject, $message);

      header ("location:bio.html")

 ?>

cheers to all :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.