quagmire02 All American 44225 Posts user info edit post |
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 |
DPK All American 2390 Posts user info edit post |
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 |
quagmire02 All American 44225 Posts user info edit post |
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 |
BigMan157 no u 103354 Posts user info edit post |
if clause?
if($poop != "") {$body=$poop."\n";} 11/24/2006 9:22:27 PM |
HaLo All American 14263 Posts user info edit post |
not quite, its got to be a strcmp function
if (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 |
BigMan157 no u 103354 Posts user info edit post |
i've used it the way i wrote it and it's worked fine
might depend on what version of PHP you're running though 11/24/2006 9:29:11 PM |
qntmfred retired 40726 Posts user info edit post |
PHP can do direct string comparison, but you should really get in the habit of using strcmp 11/24/2006 10:20:12 PM |
quagmire02 All American 44225 Posts user info edit post |
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 |
quagmire02 All American 44225 Posts user info edit post |
bttt 11/25/2006 5:42:58 PM |
quagmire02 All American 44225 Posts user info edit post |
anyone know how to do this? please tell me 11/25/2006 9:01:41 PM |
BigMan157 no u 103354 Posts user info edit post |
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;
with
if (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 |
quagmire02 All American 44225 Posts user info edit post |
^ i'll try that out tomorrow...thanks! 11/25/2006 9:46:58 PM |
robster All American 3545 Posts user info edit post |
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 |
mienutzich All American 4300 Posts user info edit post |
wheres this page hosted? I want to use this form to spam people. 11/25/2006 11:52:09 PM |
quagmire02 All American 44225 Posts user info edit post |
^^ i have, actually...got a 4 on my AP comp sci exam in high school
that 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 dumbass
thanks 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 |
qntmfred retired 40726 Posts user info edit post |
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 |
quagmire02 All American 44225 Posts user info edit post |
^ thank you...i'll take a look at those tonight
and 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 |
qntmfred retired 40726 Posts user info edit post |
go for it 11/27/2006 1:20:24 PM |
bous All American 11215 Posts user info edit post |
strip them slashes 11/27/2006 3:45:15 PM |