Jump to content

phpmailer code help


Codeman0013

Recommended Posts

I have a mailer page and it should take the post information and send it in email to me all i get in the email right now are the fields like Name: with nothing after it and so on i'm going to attach my email page and my page thats sending it so you can look and hopefully someone can help me here..

<?php// Set things up here$Name = $_POST['fieldname'];$Address = $_POST['fieldaddress'];$City = $_POST['fieldcity'];$State = $_POST['fieldstate'];$Zip = $_POST['fieldzip'];$Phone = $_POST['fieldphone'];$Fax = $_POST['fieldfax'];$Email = $_POST['fieldemail'];$to	  = 'isintern@jonesthomas.com';$headers = 'From: ilsoy'.	$subject = 'Rust Watchers application';// Start the message$message = "Hello the following person has requested to join Rust Watchers\nName: $fieldname\nAddress: $fieldaddress\nCity: $fieldcity\nState: $fieldstate\nZip: $fieldzip\nPhone: $fieldphone\nFax: $fieldfax\nEmail: $fieldemail\n";// Finally send it off.if(mail($to, $subject, $message, $headers)){  header("Location: /about/programs/rust-watchers/");}else{  header("Location: /about/programs/rust-watchers/apply-for-rust-watchers/test2.php");}?>

here is the page sending the email page its info...

<?phpforeach($_POST as $key){  $_POST[$key] = stripslashes(trim(str_replace("'","",$_POST[$key])));}print "Name: $_POST[fieldname]<br/>";print "Address: $_POST[fieldaddress]<br/>";print "City: $_POST[fieldcity]<br/>";print "State: $_POST[fieldstate]<br/>";print "Zip: $_POST[fieldzip]<br/>";print "Phone: $_POST[fieldphone]<br/>";print "Fax: $_POST[fieldfax]<br/>";print "Email: $_POST[fieldemail]<br/>";print "<form action=\"/about/programs/rust-watchers/apply-for-rust-watchers/mailapp.php\" action=\"POST\">";foreach($_POST as $key){  print "<input type=\"hidden\" name=\"$key\" value=\"$_POST[$key]\" />";}print "<input type=\"submit\" value=\"Submit\" /></form>";?> <form action="/about/programs/rust-watchers/apply-for-rust-watchers/mailapp.php" method="post"><input type="hidden" name="fieldname" value="$_POST['fieldname']"><input type="hidden" name="fieldaddress" value="$_POST['fieldaddress']"><input type="hidden" name="fieldcity" value="$_POST['fieldcity']"><input type="hidden" name="fieldstate" value="$_POST['fieldstate']"><input type="hidden" name="fieldzip" value="$_POST['fieldzip']"><input type="hidden" name="fieldphone" value="$_POST['fieldphone']"><input type="hidden" name="fieldfax" value="$_POST['fieldfax']"><input type="hidden" name="fieldemail" value="$_POST['fieldemail']"><input type="submit" name="submit" value="Send Email"><input type="submit" name="submit" value="Edit Info"></form>

Link to comment
Share on other sites

Well, it may not seem obvious to you but it is extremly obvious to me. You have your variables mixed up..$Name = $_POST['fieldname'];Name: $fieldname\nSo you accidently took the form names and used them as variables, so just remove the 'field' section and it should work great.. just remember that variables dont change names lol.

Link to comment
Share on other sites

I did something like this for a project in college. I don't really have an answer to your question, but I have a suggestion.When using php mailer code, make sure you are being very secure.About a week after I published the project online, I received notice from the schools IT department that the script I created was hacked and used to send out MASS AMOUNTS of spam email. The ISP shut down the servers internet access. I had to do everything locally for about 2 months.

Link to comment
Share on other sites

Well, it may not seem obvious to you but it is extremly obvious to me. You have your variables mixed up..$Name = $_POST['fieldname'];Name: $fieldname\nSo you accidently took the form names and used them as variables, so just remove the 'field' section and it should work great.. just remember that variables dont change names lol.
hey i removed the field name part and it still just sends me a blank email i'm going to put the new revised code up here....this is the page that sends the info over...
<form action="/about/programs/rust-watchers/apply-for-rust-watchers/mailapp.php" method="post"><input type="hidden" name="name" value="$_POST['name']"><input type="hidden" name="address" value="$_POST['address']"><input type="hidden" name="city" value="$_POST['city']"><input type="hidden" name="state" value="$_POST['state']"><input type="hidden" name="zip" value="$_POST['zip']"><input type="hidden" name="phone" value="$_POST['phone']"><input type="hidden" name="fax" value="$_POST['fax']"><input type="hidden" name="email" value="$_POST['email']"><input type="submit" name="submit" value="Send Email"><input type="submit" name="submit" value="Edit Info"></form>

email page its self...

<?php// Set things up here$Name = $_POST['name'];$Address = $_POST['address'];$City = $_POST['city'];$State = $_POST['state'];$Zip = $_POST['zip'];$Phone = $_POST['phone'];$Fax = $_POST['fax'];$Email = $_POST['email'];$to	  = 'isintern@jonesthomas.com';$headers = 'From: ilsoy'.	$subject = 'Rust Watchers application';// Start the message$message = "Hello the following person has requested to join Rust Watchers\nName: $name\nAddress: $address\nCity: $city\nState: $state\nZip: $zip\nPhone: $phone\nFax: $fax\nEmail: $email\n";// Finally send it off.if(mail($to, $subject, $message, $headers)){  header("Location: /about/programs/rust-watchers/");}else{  header("Location: /about/programs/rust-watchers/apply-for-rust-watchers/test2.php");}?>

Link to comment
Share on other sites

well, it looks like you never really send it rofl. Try putting the mail function inside the if.. also in the if statement like it is..
well it does send me an email just no information in the email but blank fields so if i move that inside it it will work then?
Link to comment
Share on other sites

Be consistent with your variable names. What skym means is that you can't call a variable $Name in one place, and use $name somewhere else. $Name and $name are two different variables. You need to be consistent.Also, about the script being used to send spam, you probably shouldn't make a publicly-accessible email script that allows you to specify the "to" address. It would obviously be trivial to write a program to keep sending that script information that it would email out.

Link to comment
Share on other sites

Be consistent with your variable names. What skym means is that you can't call a variable $Name in one place, and use $name somewhere else. $Name and $name are two different variables. You need to be consistent.Also, about the script being used to send spam, you probably shouldn't make a publicly-accessible email script that allows you to specify the "to" address. It would obviously be trivial to write a program to keep sending that script information that it would email out.
its not specifying the to address at all thats just the person submiting their email for future reference if needed there is no place where they put their to address the script does it all but right now its not calling the information on the page needed to send it to the email page its just simply printing it and i'm having issues with it and i dont know if i will ever get it working...
<?phpforeach($_POST as $key){  $_POST[$key] = stripslashes(trim(str_replace("'","",$_POST[$key])));}print "Name: $_POST[fieldname]<br/>";print "Address: $_POST[fieldaddress]<br/>";print "City: $_POST[fieldcity]<br/>";print "State: $_POST[fieldstate]<br/>";print "Zip: $_POST[fieldzip]<br/>";print "Phone: $_POST[fieldphone]<br/>";print "Fax: $_POST[fieldfax]<br/>";print "Email: $_POST[fieldemail]<br/>";foreach($_POST as $key){  print "<input type=\"hidden\" name=\"$key\" value=\"$_POST[$key]\" />";}?><form action="/about/programs/rust-watchers/apply-for-rust-watchers/mailapp.php" method="post"><input type="hidden" name="fieldname" value="<?php $_POST['fieldname']?>"><input type="hidden" name="fieldaddress" value="<?php $_POST['fieldaddress']?>"><input type="hidden" name="fieldcity" value="<?php $_POST['fieldcity']?>"><input type="hidden" name="fieldstate" value="<?php $_POST['fieldstate']?>"><input type="hidden" name="fieldzip" value="<?php $_POST['fieldzip']?>"><input type="hidden" name="fieldphone" value="<?php $_POST['fieldphone']?>"><input type="hidden" name="fieldfax" value="<?php $_POST['fieldfax']?>"><input type="hidden" name="fieldemail" value="<?php $_POST['fieldemail']?>"><input type="submit" name="submit" value="Send Email"><input type="submit" name="submit" value="Edit Info"></form>

i dont think its right still its not sending anything to the next page at all like it should i'm just totally lost and like i said i'm a newbie on the whole php mail thing

Link to comment
Share on other sites

Yeah, you've got a few issues. Compare this code with what you have and see if you can find why this works and yours doesn't, there are quite a few changes:

<?phpforeach($_POST as $key => $value){  $_POST[$key] = stripslashes(trim(str_replace("'","",$_POST[$key])));}print "Name: {$_POST['fieldname']}<br/>";print "Address: {$_POST['fieldaddress']}<br/>";print "City: {$_POST['fieldcity']}<br/>";print "State: {$_POST['fieldstate']}<br/>";print "Zip: {$_POST['fieldzip']}<br/>";print "Phone: {$_POST['fieldphone']}<br/>";print "Fax: {$_POST['fieldfax']}<br/>";print "Email: {$_POST['fieldemail']}<br/>";foreach($_POST as $key => $value){  print "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\" />";}?><form action="/about/programs/rust-watchers/apply-for-rust-watchers/mailapp.php" method="post"><input type="hidden" name="fieldname" value="<?php print $_POST['fieldname']?>"><input type="hidden" name="fieldaddress" value="<?php print $_POST['fieldaddress']?>"><input type="hidden" name="fieldcity" value="<?php print $_POST['fieldcity']?>"><input type="hidden" name="fieldstate" value="<?php print $_POST['fieldstate']?>"><input type="hidden" name="fieldzip" value="<?php print $_POST['fieldzip']?>"><input type="hidden" name="fieldphone" value="<?php print $_POST['fieldphone']?>"><input type="hidden" name="fieldfax" value="<?php print $_POST['fieldfax']?>"><input type="hidden" name="fieldemail" value="<?php print $_POST['fieldemail']?>"><input type="submit" name="submit" value="Send Email"><input type="submit" name="submit" value="Edit Info"></form>

Link to comment
Share on other sites

Yes, and there already is a foreach to print the input fields, but those were not contained within the <form> tags. So this should be enough:

<?phpforeach($_POST as $key => value){  $_POST[$key] = stripslashes(trim(str_replace("'","",$_POST[$key])));}print "Name: {$_POST['fieldname']}<br/>";print "Address: {$_POST['fieldaddress']}<br/>";print "City: {$_POST['fieldcity']}<br/>";print "State: {$_POST['fieldstate']}<br/>";print "Zip: {$_POST['fieldzip']}<br/>";print "Phone: {$_POST['fieldphone']}<br/>";print "Fax: {$_POST['fieldfax']}<br/>";print "Email: {$_POST['fieldemail']}<br/>";?><form action="/about/programs/rust-watchers/apply-for-rust-watchers/mailapp.php" method="post"><?phpforeach($_POST as $key => $value){  print "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\" />";}?><input type="submit" name="submit" value="Send Email"><input type="submit" name="submit" value="Edit Info"></form>

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...