okay, let's say i want to do a guestbook or contact form or whatever using php...i can get it to send simple things, but i want it to send a number of input fields in the body part of the mail() function...okay, so here's what my php looks like:<?php $sendto = "whatever@whatever.com"; $subject = "Web Contact Form"; $thankyou = "index.php?p=thankyou"; $emptyfields = "index.php?p=emptyfields"; $name = $_REQUEST['name']; $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $address = $_REQUEST['address']; $city = $_REQUEST['city']; $state = $_REQUEST['state']; $zip = $_REQUEST['zip']; $comments = $_REQUEST['comments'];mail($sendto, $subject, $name);?>what i have above works fine...but instead of just $name, i want to send the rest of variables at the same time...i've googled it, but i'm still not entirely sure what i'm looking for, so it makes it difficult to search EDIT: well, i found something that works, maybe this is the only way to do it...added this to the end:$body = $name."\n";$body .= $email."\n";$body .= $phone;mail($sendto, $subject, $body);it works...is there a simpler way to do this?[Edited on November 24, 2006 at 6:21 PM. Reason : .]
11/24/2006 6:05:07 PM
Tried just doing:mail($sendto, $subject, $_REQUEST);You could also do a loop and generate all that $body stuff. I haven't done php in a while so I don't know what'd happen. Most of what I do now at my job is ColdFusion.That or:$body = "{$_REQUEST['name']}\n{$_REQUEST['email']}\n...etc...";[Edited on November 24, 2006 at 6:30 PM. Reason : -]
11/24/2006 6:28:36 PM
okay, my next question...how do i exclude empty fields from the email? for example, if the person provides a name and a phone number and nothing else, how do check those fields for content and then remove them from $body if they're blank?
11/24/2006 9:12:12 PM
if clause?if($poop != "") {$body=$poop."\n";}
11/24/2006 9:22:27 PM
not quite, its got to be a strcmp functionif (strcmp($poo, "")!=0) {print $poo}change to your variables and purposes[Edited on November 24, 2006 at 9:26 PM. Reason : parenthesis]
11/24/2006 9:26:09 PM
i've used it the way i wrote it and it's worked finemight depend on what version of PHP you're running though
11/24/2006 9:29:11 PM
PHP can do direct string comparison, but you should really get in the habit of using strcmp
11/24/2006 10:20:12 PM
i'm not at all familiar with strcmp...how would i implement that into the following code, to search the complete contents of $body?<?php$sendto = "whatever@whatever.com";$subject = "Web Contact Form";$thankyou = "index.php?p=thankyou";$emptyfields = "index.php?p=emptyfields";$sitename = "website_name";$name = $_REQUEST['name'];$email = $_REQUEST['email'];$phone = $_REQUEST['phone'];$address = $_REQUEST['address'];$city = $_REQUEST['city'];$state = $_REQUEST['state'];$zip = $_REQUEST['zip'];$comments = $_REQUEST['comments'];$body = $name."\n";$body .= "Email: ".$email."\n";$body .= "Phone: ".$phone."\n\n";$body .= $address."\n";$body .= $city.", ".$state." ".$zip."\n\n";$body .= "Comments: ".$comments;$headers = "From: ".$sitename."\n" . "Return-Path: ".$email."\n" . "Reply-To: ".$email."\n";if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}if(empty($name)){ header("location:$emptyfields"); exit;}else { mail($sendto, $subject, $body, $headers); header("location:$thankyou");}?>
11/25/2006 8:50:15 AM
bttt
11/25/2006 5:42:58 PM
anyone know how to do this? please tell me
11/25/2006 9:01:41 PM
replace$body = $name."\n";$body .= "Email: ".$email."\n";$body .= "Phone: ".$phone."\n\n";$body .= $address."\n";$body .= $city.", ".$state." ".$zip."\n\n";$body .= "Comments: ".$comments;withif (strcmp($name, "")!=0) $body = $name."\n";if (strcmp($email, "")!=0) $body .= "Email: ".$email."\n";if (strcmp($phone, "")!=0) $body .= "Phone: ".$phone."\n\n";if (strcmp($address, "")!=0) $body .= $address."\n";if (strcmp($city, "")!=0 && strcmp($state, "")!=0 && strcmp($zip, "")!=0) $body .= $city.", ".$state." ".$zip."\n\n";if (strcmp($comments, "")!=0) $body .= "Comments: ".$comments;something along those lines
11/25/2006 9:15:00 PM
^ i'll try that out tomorrow...thanks!
11/25/2006 9:46:58 PM
have you taken any csc classes or completed any basic programming tutorials or anything??If you are trying to use php, do yourself and everyone else a favor and at least learn what an if statement is used for.
11/25/2006 10:58:03 PM
wheres this page hosted? I want to use this form to spam people.
11/25/2006 11:52:09 PM
^^ i have, actually...got a 4 on my AP comp sci exam in high schoolthat was also 5 and a half years ago...i'm not a csc major, i haven't taken in any csc classes, and i thought i'd screw around with php...the basics are easy...i don't recall saying anything about if statements, but i DO recall stating that i was unfamiliar with strcmp and its syntax, you dumbassthanks for the advice, you contributed much to the quality of this thread ^ i'm not done...i've put in a FEW checks to minimize that possibility, but it's for a very tiny non-profit site, so i'm not concerned about it
11/27/2006 10:02:12 AM
full documentation is available at http://www.php.net. it's a very useful resource for php. see http://www.php.net/strcmp for syntax and whatnot[Edited on November 27, 2006 at 11:26 AM. Reason : not to mention http://www.php.net/mail]
11/27/2006 11:25:03 AM
^ thank you...i'll take a look at those tonightand if anyone cares, i'll post the completed script...i'd like to get comments on security shortcomings, as well as general construction
11/27/2006 12:51:43 PM
go for it
11/27/2006 1:20:24 PM
strip them slashes
11/27/2006 3:45:15 PM