Jump to content

Mail my @$$


mikeumus

Recommended Posts

I'm really immune to becoming addicted to PHP at the moment as I am at the bottom of the learning curve.

 

There are a million mail() tutorials out there, but the ones I've found are not for form submission I guess because they all expect that $message should definetly be enough, why would you want any more than that!?

 

I've re-arranged my code sooooooooooo much, adding 's and "s everytime I make a change to every var in my array. I had to stop. And now I'm here.

 

Here's the code:  :'(

 

<?php

$email=$_REQUEST['email'];

$title=$_REQUEST['title'];

$name=$_REQUEST['name'];

$tag=$_REQUEST['tag'];

$country=$_REQUEST['country'];

$address=$_REQUEST['address'];

$cap=$_REQUEST['cap'];

$date=$_REQUEST['date'];

$prize=$_REQUEST['prize'];

$ruleSet=$_REQUEST['ruleSet'];

$customRule=$_REQUEST['customRule'];

$detail=$_REQUEST['detail'];

$message=array('$title','$name','$tag','$country','$address','$cap','$date','$prize','$ruleSet','$customRule','$detail');

$m=implode(" ",$message);

mail("mikeumus@gmail.com","L4DT Form Submission","$m","From: $email");

header("Location:thankyou.htm");

?>

 

 

Link to comment
Share on other sites

dont use $_REQUEST, makes hacking your site way too easy

 

use this format

 

if smpt is enabled on your server, this format will send an emai

 

$to      = $email;
$subject = 'put your subject here';
$message = "put your message here";
$message = wordwrap($message, 70);// helps with formatting on the recieving end
$headers = 'From: ' . $email . "\r\n" .
    'Reply-To: ' . $email . "\r\n";//make sure to define your to/froms
mail($to, $subject, $message, $headers);

Link to comment
Share on other sites

Thanks for the response Lodius2000, but but if not REQUEST then where am I getting my form information from? I don't see how your getting it in your code example.

 

Plus, how do I add all my forms information into the email??

 

All this:

 

'$title','$name','$tag','$country','$address','$cap','$date','$prize','$ruleSet','$customRule','$detail'

 

I am receiving an email in my tests but it's blank.

 

 

 

Link to comment
Share on other sites

In your form, make sure each form element has name='nameofvariablehere' in it.  Make sure to use the post method for your form (inside your form tag, do method='post').  In your processing script (the one you posted), use

 

$nameofvariablehere = $_POST['nameofvariablehere']; // <--vars will be in $_POST array

 

Beyond that...

 

 

In your array you are using single quotes around your variables.  Single quotes causes php to interpret the string literally.  If you want it to use the value of the variable instead of the literal variable name, use double quotes.  Or better yet, since you are wanting each array element to be only the variable values, don't use quotes at all.

 

But then again, I don't really see the point in making an array out of all your variables in the first place, seeing as how you turn around and implode it. Just make a single string in the first place.

 

 

 

 

Link to comment
Share on other sites

switch all instances of $_REQUEST to $_POST in all of your scripts and change your form method to POST, unless you have anything that you must pass through your url like 'index.html?id=2', then you need to use $_GET to retrieve those variables. post passes all form variables silently to the form destination, get passes all of them in the url, request passes them all via either method, you dont want to see

 

login.php?username=mikumus&password=yourrealpasswordinplaintext

 

so you use post

// read http://shiflett.org/articles/cross-site-request-forgeries for more or do a quick google search on dangers of $_request

 

 

no on to your email... use my method, especially the $headers var because some mail servers if will toss it right into spam if you send an email without a relpy-to

 

if you are getting a blank email then it means your '$title','$name','$tag','$country','$a.. isnt being passed to $m correctly

 

for one you dont need the single quotes (correct me if im wrong forum) so

$message=array($title,$name,$tag,$country,$address,$cap,$date,$prize,$ruleSet,$customRule,$detail);

$message=implode(" ",$message);

 

should do it

Link to comment
Share on other sites

I'm pretty confident I know what's wrong with my code now.

 

There is an initial post.php where user enter in the forms information that form reads:

 

<form action="formHandler.php" method="post">

 

Then the next page spits the info they entered back at them to double check what they entered:

 

<h3><span title="Left 4 Dead Versus Tournament Submission Form" style="text-decoration:underline">Left 4 Dead Versus Tournament Submission Form</span></h3><br>

<br/>

<br/>Please take a moment to review your entry, making sure it's correct before submission.<br/><br/>

You entered:<br/><br/>

Tournament Title: <?php echo($_POST['title'])?> <br/>

Host's Name: <? echo($_POST['name'])?> <br/>

Host's E-Mail: <?php echo($_POST['email'])?> <br/>

Host's Tag/Username:<?php echo($_POST['tag'])?> <br/>

Country/Territoy: <?php echo($_POST['country'])?> <br/>

Location: <?php echo($_POST['address'])?> <br/>

Sign-up Cap: <?php echo($_POST['cap'])?> <br/>

Date(s): <?php echo($_POST['date'])?> <br/>

Prize(s): <?php echo($_POST['prize'])?> <br/>

Rule Set: <?php echo($_POST['ruleSet'])?> <br/>

Custom Rule(s): <?php echo($_POST['customRule'])?> <br/>

Description: <?php echo($_POST['detail'])?> <br/><br/>

<form method="post" action="sendPost.php">

<input type="button" onClick="history.go(-1)" value="Back">

<input type="submit" value="Submit">

</form>

 

Then sendPost.php, the code we've wrongly been discussing because of my ignorance:

 

<?php

$email=$_POST['$email'];

$title=$_POST['$title'];

$name=$_POST['$name'];

$tag=$_POST['$tag'];

$country=$_POST['$country'];

$address=$_POST['$address'];

$cap=$_POST['$cap'];

$date=$_POST['$date'];

$prize=$_POST['$prize'];

$ruleSet=$_POST['$ruleSet'];

$customRule=$_POST['$customRule'];

$detail=$_POST['$detail'];

$message=array($title,$name,$tag,$country,$address,$cap,$date,$prize,$ruleSet,$customRule,$detail);

$m=implode(" ",$message);

mail("mikeumus@gmail.com","L4DT Form Submission","$m","From: $email");

header("Location:thankyou.htm");

?>

 

So I'm guessing(and guessing correctly, that the form information isn't making it from the second page into sendPost.php, right?

 

So on the second page, I though I could I do this to get the data from the second page to sendPost.php like the million posts on the PHP.net mail - Manual:

 

<?php

$message .= "Tournament Title: echo($_POST['title']) <br/>";

$message .= "Host's Name: echo($_POST['name']) <br/>";

$message .= "Host's E-Mail: echo($_POST['email']) <br>";

$message .= "Host's Tag/Username: echo($_POST['tag']) <br/>";

$message .= "Country/Territoy:  echo($_POST['country']) <br/>";

$message .= "Location:  echo($_POST['address']) <br/>";

$message .= "Sign-up Cap:  echo($_POST['cap']) <br/>";

$message .= "Date(s): echo($_POST['dates']) <br/>";

$message .= "Prize(s):  echo($_POST['prize']) <br/>";

$message .= "Rule Set:  echo($_POST['ruleSet']) <br/>";

$message .= "Custom Rule(s):  echo($_POST['customRule']) <br/>";

$message .= "Description:  echo($_POST['detail']) <br/><br/>";

?>

 

But this causes this error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/i/k/mikeumus/html/l4dt.com/formHandler.php on line 72

 

 

Every single comment on that manual has BS like this: $message .=

 

and for what? What are they using their html mail for? It seems useless is that manual old, i'm freaking out.  >:(

 

 

 

 

Link to comment
Share on other sites

Here's a nice little form handler I wrote some time ago.

 

It can be used with either _GET or _POST.

 

You can set the REDIRECT and SUBJECT in your Form or just set it at the top of the script here.

 

This form handler sends the message to a single address and that's it - set in the script.

 

<?php

// $mail_to and $mail_from must be set.

$mail_to = 'to.someone@someplace.com'; // Who is the E-Mail going to? ex: me@mydomain.com
$mail_from = 'where@i.am.from.com'; // Where does the E-Mail appear to be from? ex; webform@mydomain.com

// OPTIONAL SETTING
$redirect_url = ''; // Example: http://domain.com/thankyou.html - must be a FULL URL.

   ############################
   #  DO NOT EDIT BELOW THIS  #
   ############################

// Fail if _POST and _GET are empty. Nothing to process.
if(count($_POST) == 0 AND count($_GET) == 0):
        echo 'This form handler does nothing if visited directly. You must submit form data to this script.';
        exit;
endif;

// Fail if $mail_to or $mail_from are not set.
if(empty($mail_to) OR empty($mail_from)):
        echo 'You must edit this script and set the appropriate values for $mail_to and $mail_from.';
        exit;
endif;

// Set $fields to whichever method is being used.
$fields = (count($_POST) > 0 ) ? $_POST : $_GET;

$message_body = "Form Submission \n\n";

foreach ($fields as $field => $value):
        switch(strtolower($field)):
                case 'redirect':
                        $redirect = $value;
                break;
                case 'subject':
                        $subject = $value;
                break;
        endswitch;
        if (strtolower($field) != 'redirect' AND strtolower($field) != 'submit' AND strtolower($field) != 'subject'):
                $message_body .= strtoupper($field) . ": {$value}\r\n";
        endif;
endforeach;

// Set the redirect URL from the form (if set). $host_url is a default action if $redirect isn't set
$redirect = (empty($redirect_url)) ? $redirect : $redirect_url;
$host_url = $_SERVER['HTTP_HOST'];

// Set the message subject based upon a subject field being set or not.

$message_subject = (!empty($subject)) ? $subject : 'Message from '.$_SERVER['HTTP_HOST'];

$headers = "From: {$mail_from}\r\n
Reply-To: {$mail_from}\r\n
X-Mailer: PHP/" . phpversion();

if (!mail($mail_to, $message_subject, $message_body, $headers)):
        echo 'Messge Send Failed.';
endif;

if(empty($redirect)):
        header("Location: http://{$host_url}");
else:
        header("Location: {$redirect}");
endif;

Link to comment
Share on other sites

Thanks awpti, i'll definetly apply that to my code once I get it working.

 

Crayon Violent, No error now, but no info passed again. I really wish you guys could see the big picture, so now you can:

 

Here's waht's important in each file:

 

Post.php:

 

...<form action="formHandler.php" method="post">...

 

<input onMouseOver="cursor(pointer)" type="reset" value="Reset">

<input type="submit" value="Next">

</form>

 

formHandler.php:

 

<?php

$message .= "Tournament Title: {$_POST['title']} <br/>";

$message .= "Host's Name: {$_POST['name']} <br/>";

$message .= "Host's E-Mail: {$_POST['email']} <br>";

$message .= "Host's Tag/Username: {$_POST['tag']} <br/>";

$message .= "Country/Territoy: {$_POST['country']} <br/>";

$message .= "Location: {$_POST['address']} <br/>";

$message .= "Sign-up Cap: {$_POST['cap']} <br/>";

$message .= "Date(s): {$_POST['dates']} <br/>";

$message .= "Prize(s): {$_POST['prize']} <br/>";

$message .= "Rule Set: {$_POST['ruleSet']} <br/>";

$message .= "Custom Rule(s):  {$_POST['customRule']} <br/>";

$message .= "Description:  {$_POST['detail']} <br/><br/>";

?>

<form method="post" action="sendPost.php">

<input type="button" onClick="history.go(-1)" value="Back">

<input type="submit" value="Submit">

</form>

 

sendPost.php in it's entirety:

 

<?php

$email=$_POST['$email'];

$title=$_POST['$title'];

$name=$_POST['$name'];

$tag=$_POST['$tag'];

$country=$_POST['$country'];

$address=$_POST['$address'];

$cap=$_POST['$cap'];

$date=$_POST['$dates'];

$prize=$_POST['$prize'];

$ruleSet=$_POST['$ruleSet'];

$customRule=$_POST['$customRule'];

$detail=$_POST['$detail'];

$message=$_GET['$message'];

mail("mikeumus@gmail.com","L4DT Form Submission","$message","From: $email");

header("Location:thankyou.htm");

?>

 

The info's not getting to sendPost.php, but I know I've had the mail code working at differnt times tonight casue I've gotten emails with content like:

 

array

 

and

 

$title,$name,$tag,$country,$address,$cap,$date,$prize,$ruleSet,$customRule,$detail

 

And I took the 's off

$title,$name,$tag,$country,$address,$cap,$date,$prize,$ruleSet,$customRule,$detail

 

tried that, blank emial.

 

I used "s instead, blank email, so the form information isn't getting to sendPost.php

 

 

>:( >:(>:( ??? ??? ??? :-\ :-\ :-\ :'( :'( :'(

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

The information isn't getting to sendPost.php because you're not sending it. You would have to put all of the information into hidden values in the second form for that to work or you could use sessions:

 

In formHandler.php

<?php
session_start();
$message = "Tournament Title: {$_POST['title']} <br/>";
$message .= "Host's Name: {$_POST['name']} <br/>";
$message .= "Host's E-Mail: {$_POST['email']} <br>";
$message .= "Host's Tag/Username: {$_POST['tag']} <br/>";
$message .= "Country/Territoy: {$_POST['country']} <br/>";
$message .= "Location: {$_POST['address']} <br/>";
$message .= "Sign-up Cap: {$_POST['cap']} <br/>";
$message .= "Date(s): {$_POST['dates']} <br/>";
$message .= "Prize(s): {$_POST['prize']} <br/>";
$message .= "Rule Set: {$_POST['ruleSet']} <br/>";
$message .= "Custom Rule(s):  {$_POST['customRule']} <br/>";
$message .= "Description:  {$_POST['detail']} <br/><br/>";
$_SESSION['message'] = $message;
$_SESSION['email'] = $_POST['email'];
?>
<form method="post" action="sendPost.php">
<input type="button" onClick="history.go(-1)" value="Back">
<input type="submit" value="Submit">
</form>

 

In sendPost.php

<?php
session_start();
$message=$_SESSION['message'];
$email = $_SESSION['email'];
mail("mikeumus@gmail.com","L4DT Form Submission","$message","From: $email");
header("Location:thankyou.htm");
?>

 

Ken

Link to comment
Share on other sites

Wow, thanks kenrbnsn. I already learning alot just from this thread.

 

What is the session command?

 

So I inserted your code into formHandler.php and sendPost.php and got this error on my formHandler.php(the second page):

 

_____________________________________________________________

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/k/mikeumus/html/l4dt.com/formHandler.php:8) in /home/content/m/i/k/mikeumus/html/l4dt.com/formHandler.php on line 73

 

_____________________________________________________________

 

Is this because of my Google Analytics code? Can I create a separate instance of the session_start function?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.