Jump to content

Archived

This topic is now archived and is closed to further replies.

perezf

Php emailer help

Recommended Posts

i cant seem to figure out what is going wrong im sure it is something simple

but the email function is not working

[code]<div align="center">
<form name="form1" method="post" action="">
  <p>Your Name:<br>
    <input name="name" type="text" size="50">
  </p>
  <p>Your Email:<br>
    <input name="from" type="text" size="50">
  </p>
  <p>Your Question:<br>
    <textarea name="contents" cols="50" rows="5"></textarea>
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit"> 
    </p>
</form></div>

<?php

if(isset($_POST['Submit'])){}else{

$to = "2fr3sh@gmail.com";
$subject = "Question from DoitYourself";
$from_header = "From: $from";


  mail($to, $subject, $contents, $from_header);



echo "Thank You for using the 2fr3sh emailer the messages have been sent!";
};

?>[/code]

Share this post


Link to post
Share on other sites
you have your isset function wrong. Also if you have globals turned off, which they are by default, you cannot just use $from.

try this
[code]
<?php
if(isset($_POST['Submit'])){
$to = "2fr3sh@gmail.com";
$subject = "Question from DoitYourself";
$from_header = "From: $_POST['from']";


  mail($to, $subject, $contents, $from_header);



echo "Thank You for using the 2fr3sh emailer the messages have been sent!";
} else {
?>
<div align="center">
<form name="form1" method="post" action="">
  <p>Your Name:<br>
    <input name="name" type="text" size="50">
  </p>
  <p>Your Email:<br>
    <input name="from" type="text" size="50">
  </p>
  <p>Your Question:<br>
    <textarea name="contents" cols="50" rows="5"></textarea>
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit"> 
    </p>
</form></div>

<?
}
?>[/code]

Share this post


Link to post
Share on other sites
[code]
<form name="form1" method="post" action="">
[/code]

You have not defined [b]action[/b] in your form, so the data you submit doesn't get sent anywhere. Try this:

[code]
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
[/code]

Share this post


Link to post
Share on other sites
good job heyray2 I blew right past that part :)

Share this post


Link to post
Share on other sites
i wouldnt recommend putting
<?php echo $_SERVER['PHP_SELF']; ?>
because it just goes to the main page index.php not to the page i want it to stay on

leaving the action blank makes the same page reload allowing the script to work now

Share this post


Link to post
Share on other sites
[code]<?php echo $_SERVER['PHP_SELF']; ?>[/code]

That variable is replaced by the name of the php file that printed out your html form, so only use it if that same php file also does your form processing.

Otherwise, enter the name of the file that you want to process the form... ;)

Share this post


Link to post
Share on other sites

×

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.