Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP -- Sending mail + if statements. 2

Status
Not open for further replies.

khanza

Technical User
Feb 20, 2003
70
US
ok -- I know sending mail works on this particular server because I tested it using -
This script
Code:
<?php
$to = "enduser@aol.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body))
{
   echo("<p>Message sent!</p>");
}
else
{
   echo("<p>Message delivery failed...</p>");
}
?>


So now I'm trying to do this --
Code:
<html>
<?php echo($_POST['name']); ?> <?php echo($_POST['birth']); ?>
<?php
if ($submit == 1 )
    $to = "enduser@aol.com";
    $subject = $_POST['name'];
    $body = $_POST['birth'];
        if (mail($to, $subject, $body))
        {
           echo("<p>Message sent!</p>");
        }
    else
    {
       echo("<p>Message delivery failed...</p>");
    }
?>
</html>

Basically, I was just trying to modify the original code (top code) to send my post vars to me.

So I attempted, I failed,
Any help?

Thanks guys,
Khan
 
Your code is also missing some brackets:

Where do you assign a value to $submit?
Code:
<html>
<?php
echo($_POST['name']);
echo($_POST['birth']);
if ($submit == 1 ){
  $to = "enduser@aol.com";
  $subject = $_POST['name'];
  $body = $_POST['birth'];
  if (mail($to, $subject, $body)){
    echo("<p>Message sent!</p>");
  }
  else{
    echo("<p>Message delivery failed...</p>");
  }
} //closes the original if statement: (if ($submit ==1))
?>
</html>

if you don't assign a value to submit, try this:
Code:
<html>
<?php
echo($_POST['name']);
echo($_POST['birth']);
if ($_POST['submit']){ //assuming your submit button is called submit (case sensitive)
  $to = "enduser@aol.com";
  $subject = $_POST['name'];
  $body = $_POST['birth'];
  if (mail($to, $subject, $body)){
    echo("<p>Message sent!</p>");
  }
  else{
    echo("<p>Message delivery failed...</p>");
  }
} //closes the original if statement: (if ($_POST['submit']))
?>
</html>

[cheers]
Cheers!
Laura
 
ooo man laura -- If you were here, I would be hugging you!

Thank you soooo much, and your comments were very helpful!

Alex
 
Here's another question....

In the email -- I want it to send multiple var's in the body -- So I tried the Var's with commas and with spaces -- neither works.... Any ideas?

Code:
<html>
<?php
// echo($_POST['name']);
// echo($_POST['email']);
if ($_POST['submit']){ //assuming your submit button is called submit (case sen$
  $to = "totalgeekdom@gmail.com";
  $subject = $_POST['name'];
  $body = $_POST['name'] $_POST['email'] $_POST['sex'] $_POST['pass'];
  if (mail($to, $subject, $body)){
    echo("<p>Message sent!</p>");
  }
  else{
    echo("<p>Message delivery failed...</p>");
  }
} //closes the original if statement: (if ($_POST['submit']))
?>
</html>
 
You should read up on the basic PHP operators etc. The PHP manual is a great resource.
I'll answer your question, anyway, but please, go to the manual.

The dot operator '.' concatenates values.
Code:
<?
$x = "Hello";
$y = "world";
print $x.' '.$y;
?>
Also, at tek-tips new questions should be posted as a new thread. We are always glad to help, so, please help us by following the 'local' customs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top