kvnmck18 Posted September 28, 2006 Share Posted September 28, 2006 Here's the code I've been using for my email form: <?php$mymail = 'eeeeeeeeeeeeeeeeeeeeemail@kvn18.com';$cc = 'Subject for the Email';$BoDy = ' ';$BoDy = ' ';$FrOm = 'FROM:' .$_POST['name'];$FrOm .= '<';$FrOm .= $_POST['email'];$FrOm .= '>';$BoDy .= 'Name: ';$BoDy .= $_POST['name'];$BoDy .= "\n";$BoDy .= 'Email: ';$BoDy .= $_POST['email'];$BoDy .= "\n";$BoDy .= 'City: ';$BoDy .= $_POST['city'];$BoDy .= "\n";$BoDy .= 'State: ';$BoDy .= $_POST['state'];$BoDy .= "\n";$BoDy .= 'Zip: ';$BoDy .= $_POST['zip'];$BoDy .= "\n";$send = mail("$mymail", "$cc", "$BoDy", "$FrOm");if($send){echo '<html><head>';echo '<meta http-equiv="refresh" content="0;URL=http://www.myfunkysite.com/">';echo '</head><body>Random text...';echo '</body></html>';}?> It works great, but I've been to do a couple of different things with this form:1) Send it to more than one email address a) Send one to the default email Send it also to a secondary email c) Send it to the email address that was entered from the form2) Sending all the data to added to an XML doc. a)Combining the so far two PHP codes PHPFORM to XML FORM: <?$images = Array();function start_element($parser, $name, $attrs){ global $hmmm; if($name == "whatever"){ array_push($hmmm, $attrs); }}function end_element ($parser, $name){}$imagesXML_string = file_get_contents("xml.xml");$parser = xml_parser_create();xml_set_element_handler($parser, "start_element", "end_element");xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);xml_parse($parser, $imagesXML_string) or die("Error parsing XML document.");print "<br />";if($_POST['action'] == "ins"){ array_push($hmmm, Array( "name" => $_POST['name'], "email" => $_POST['email'], "city" => $_POST['city'], "state" => $_POST['state'], "zip" => $_POST['zip'])); $hmmm_final = $hmmm;}else if($_POST['action'] == "del"){ $hmmm_final = Array(); foreach($hmmm as $whatever){ if($whatever['name'] != $_POST['namr']){ array_push($hmmm_final, $whatever); } }}$write_string = "<hmmm>";foreach($hmmm_final as $whatever){ $write_string .= "<whatever name=\"$whatever[name]\" email=\"$whatever[email]\" city=\"$whatever[city]\" state=\"$whatever[state]\" zip=\"$whatever[zip]\" />";}$write_string .= "</hmmm>";$fp = fopen("xml.xml", "w+");fwrite($fp, $write_string) or die("Error writing to file");fclose($fp);print "New Content Added Successfully";print "<br />";print "<a href=\"index.php\" title=\"return\">Return</a>";?></p> I hope this is all possible. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 28, 2006 Share Posted September 28, 2006 To send to more than one address, use the CC header. Check the php.net reference for the mail function to see some examples. Link to comment Share on other sites More sharing options...
kvnmck18 Posted September 29, 2006 Author Share Posted September 29, 2006 <?php$mymail = 'me@myemaildomain.com';$cc .= $_POST['subject'];$BoDy = ' ';$BoDy = ' ';$FrOm = 'FROM:' .$_POST['1'];$FrOm .= '<';$FrOm .= $_POST['3'];$FrOm .= '>';$BoDy .= 'Name: ';$BoDy .= $_POST['1'];$BoDy .= "\n";$BoDy .= 'Email: ';$BoDy .= $_POST['2'];$BoDy .= "\n";$BoDy .= 'Send to Alternative Person, Name: ';$BoDy .= $_POST['3'];$BoDy .= "\n";$BoDy .= 'Alternative Email: ';$BoDy .= $_POST['4'];$BoDy .= "\n";$BoDy .= 'Subject: ';$BoDy .= $_POST['subject'];$BoDy .= "\n";$BoDy .= 'Comment: ';$BoDy .= $_POST['comment'];$BoDy .= "\n";$send = mail("$mymail", "$cc", "$BoDy", "$FrOm");if($send){echo '<html><head>';echo '<meta http-equiv="refresh" content="0;URL=http://www.myfunkysite.com/">';echo '</head><body>Random text...';echo '</body></html>';}?> This won't work: <?php$mymail = 'email@yahoo.com';$mymail .= $_POST['3'];$cc .= $_POST['subject'];$BoDy = ' ';$BoDy = ' ';$FrOm = 'FROM:' .$_POST['1'];$FrOm .= '<';$FrOm .= $_POST['2'];$FrOm .= '>';$BoDy .= 'Name: ';$BoDy .= $_POST['1'];$BoDy .= "\n";$BoDy .= 'Email: ';$BoDy .= $_POST['2'];$BoDy .= "\n";$BoDy .= 'Send to Alternative Person, Name: ';$BoDy .= $_POST['3'];$BoDy .= "\n";$BoDy .= 'Alternative Email: ';$BoDy .= $_POST['4'];$BoDy .= "\n";$BoDy .= 'Subject: ';$BoDy .= $_POST['subject'];$BoDy .= "\n";$BoDy .= 'Comment: ';$BoDy .= $_POST['comment'];$BoDy .= "\n";$send = mail("$mymail", "$cc", "$BoDy", "$FrOm");if($send){echo '<html><head>';echo '<meta http-equiv="refresh" content="0;URL=http://www.microcenter.com/">';echo '</head><body>Random text...';echo '</body></html>';}?> Link to comment Share on other sites More sharing options...
yoshida Posted September 29, 2006 Share Posted September 29, 2006 If you want to implement the form and the handler in one script, let the handler check wether the submit button on the form has been clicked (else display the handler).Very roughly:if (submit has been clicked) { execute handler;} else { display form;}at least that's how I do this.If you already use mysql, you may want to create a database for all recepients, and let the handler check the number of database entries and 'loop' the handler that many times. I don't have the time to explain it in detail, but this is how I'd do it.Don't forget to add a notifier at the end of the handler, with a link to the homepage. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 2, 2006 Share Posted October 2, 2006 And, again, if you want to send to more then one person, use the CC header. You have a variable called $cc, but you are using it as the subject. The CC header (which, in your code, will be in the $FrOm variable) will let you carbon copy multiple people in the email. There are examples on php.net of how to do this, in the reference for the mail function. Link to comment Share on other sites More sharing options...
Little Goat Posted October 2, 2006 Share Posted October 2, 2006 can't you just add more adresses in the to field separated by semicolons (? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now