I have tried several different variations of this code, and nothing seems to work. I am new to PHP and am trying to move away from generators and do everything myself. I have also tried putting $fullmessage parameters all under one variable heading and this did not work either. I don't know where I'm going wrong. I've spent about 5 hours so far trying to get this thing right. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "w3"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php $subject="$subject"; $message="$message"; $fname="$fname"; $lname="$lname"; $address1="$address1"; $address2="$address2"; $city="$city"; $state="$state"; $zip="$zip"; $dayphone="$dayphone"; $eveningphone="$eveningphone"; $mail_from="$email"; $fullmessage="Name: " . $lname "," . $fname . "\n"; $fullmessage="Address: " . $address1 "\n" . $address2 "\n"; $fullmessage="City:" . $city . "\n"; $fullmessage="State: " . $state . "\n"; $fullmessage="Zip: " . $zip . "\n"; $fullmessage="Day Phone: " . $dayphone . "\n"; $fullmessage="Night Phone: " . $eveningphone . "\n"; $fullmessage="Email: " . $email_from . "\n"; $header="from: $lname, $fname <$mail_from>"; '; $send_contact=mail($to,$subject,$fullmessage,$header); ?> </body> </html> here is the other way i have tried, with several variations $fullmessage="Name: " $lname "," $fname \n "Address: "$address1 \n $address2 \n "City: "$city \n "State: "$state \n "Zip: "$zip \n "Day Phone: "$dayphone \n "Night Phone: "$eveningphone \n "Email: "$email_from \n;
Instead of doing this: $subject="$subject"; PHP: ... try this: $subject=$_POST['subject']; PHP: ... assuming that these values come from a form. Also take a look at this: http://php.net/manual/en/tutorial.forms.php Oh, and to append data to a variable, you have to do it like this: $fullmessage .= "My string"; PHP: (Note the dot)
And I need to do this with all of my variables? This is related to a form. Sorry I didn't designate that at first. I've seen it with $_Request, but I am using the $_POST on the page side. The big issue I'm having is in the $fullmessage variable though, that's what is giving me all the errors?
Also to add to what nico_swd said you need to change this part of your code: $fullmessage="Name: " . $lname "," . $fname . "\n"; $fullmessage="Address: " . $address1 "\n" . $address2 "\n"; $fullmessage="City:" . $city . "\n"; $fullmessage="State: " . $state . "\n"; $fullmessage="Zip: " . $zip . "\n"; $fullmessage="Day Phone: " . $dayphone . "\n"; $fullmessage="Night Phone: " . $eveningphone . "\n"; $fullmessage="Email: " . $email_from . "\n"; PHP: to $fullmessage = "Name: " . $lname "," . $fname . "\n"; $fullmessage .= "Address: " . $address1 "\n" . $address2 "\n"; $fullmessage .= "City:" . $city . "\n"; $fullmessage .= "State: " . $state . "\n"; $fullmessage .= "Zip: " . $zip . "\n"; $fullmessage .= "Day Phone: " . $dayphone . "\n"; $fullmessage .= "Night Phone: " . $eveningphone . "\n"; $fullmessage .= "Email: " . $email_from . "\n"; PHP: When adding (concatenating) to a string you need to place a period before the equals sign. Read more here: http://php.net/manual/en/language.operators.string.php
After changing both, i'm still getting an empty email with only "name" "address" "city" "State" "zip" "day phone" "night phone" and "email" with no corresponding values. I've added the $_POST to all the defining variables as well.
This is a screenshot of the title of the email I receive after submitting the form, if this helps diagnose as well.
When you are trying to get the value from a post field you need to enter the name value like this. HTML <input type="text" name="first_name" /> PHP $first_name = $_POST['first_name']; I've fixed your code for you to get it working, there's some changes you should make and I don't have the time to rewrite this for you. Look into mail header injections, cross site scripting and error handling. These subjects can all be found on Google. Also when debugging you need to use var_dump, again Google it. New script: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php if(isset($_POST['Submit'])) { $subject = $_POST["subject"]; $message = $_POST["message"]; $fname = $_POST["fname"]; $lname = $_POST["lname"]; $address1 = $_POST["address1"]; $address2 = $_POST["address2"]; $city = $_POST["city"]; $state = $_POST["state"]; $zip = $_POST["zip"]; $dayphone = $_POST["dayphone"]; $eveningphone = $_POST["eveningphone"]; $mail_from = $_POST["email"]; $fullmessage = "Name: $lname $fname \n"; $fullmessage .= "Address: $address1 \n $address2 \n"; $fullmessage .= "City: $city \n"; $fullmessage .= "State: $state \n"; $fullmessage .= "Zip: $zip \n"; $fullmessage .= "Day Phone: $dayphone \n"; $fullmessage .= "Night Phone: $eveningphone \n"; $fullmessage .= "Email: $email_from \n"; $header="from: $lname, $fname <$mail_from>"; $to='weaverofwords@yahoo.com'; if(mail($to,$subject,$fullmessage,$header)) { echo '<p>mail sent</p>'; }else{ echo '<p>mail error</p>'; } } ?> </body> </html> Code (markup): I haven't tested this code but it should work.
Awesome, now I see where I was going wrong. Thank you very much. I used "$" way too much. thank you for adding the "if - else", since I'm learning, I was going to add that and the re-direct after I got it right, but I was at it for hours. The only thing not filled in is the email field in the email, but I will toy around with that now that I'm moving forward again. I will definately look at those links, I'm not trying to have people write my stuff for me, just show me the right way so I can eventually show others!