PDA

View Full Version : PHP - on submit -- send mail


Pozican
05-20-2005, 07:18 PM
This code sends an email on page load as opposed to on submit -- Any ideas?

<html>
<?php
$name = $_POST['name'];
$birth = $_POST['birth'];
echo($name);
echo($birth);
?>
<?php
echo "<form action=\"confirm-test.php\" method=\"post\">";
// echo "<input type=\"hidden\" value=\"$_POST['name']\" name=\"name\">";
// echo "<input type=\"hidden\" value=\"$_POST['birth']\" name=\"birth\">";
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";
?>
<?php
$to = "totalgeekdom@gmail.com";
$subject = $_POST['name'];
$body = $_POST['birth'];
if (isset($_POST['submit'])) {
mail($to, $subject, $body);
}
?>
</html>

Pozican
05-20-2005, 08:23 PM
I just tried this --

<html>
<?php
$to = "enduser@aol.com";
$subject = $_POST['name'];
$body = $_POST['birth'];
if ($_POST['submit'] == 1) {
mail($to, $subject, $body);
}
?>
<?php
$name = $_POST['name'];
$birth = $_POST['birth'];
echo($name);
echo($birth);
?>
<?php
echo "<form action=\"confirm-test.php\" method=\"post\">";
// echo "<input type=\"hidden\" value=\"$_POST['name']\" name=\"name\">";
// echo "<input type=\"hidden\" value=\"$_POST['birth']\" name=\"birth\">";
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";
?>
</html>


Still doesn't work.

Ultragames
05-20-2005, 09:48 PM
Due to the browser im stuck on here at school, i can't see the code, (on PHP works for some reason)

However, if you make a form that sends information to the page that emails on load, then it will work. PHP is not a 'live' language, it is server side. Which means you must have a seperate page to do the emailing, or check to see if the info was sent to its self.

delinear
05-21-2005, 12:34 PM
Try enclosing your mailer in an if statement maybe, like this:
<?php

if(!empty($_POST['submit'])) {
$to = "enduser@aol.com";
$subject = $_POST['name'];
$body = $_POST['birth'];

mail($to, $subject, $body);

} else {
?>

<html>
// put your form here
</html>

<?php
}
?>

wit_vivek
01-17-2011, 01:41 PM
http://www.vivekmodi.com/2011/01/sending-mail-in-php/

guys check this out its straight forward with description