/    Sign up×
Community /Pin to ProfileBookmark

send mail output file

Hi

I am sending mail with php, passing information from an html page via input.
So basicly I have two files: The html and the sendmail.php pages… And the output message (success or the failure) appears on a blank page. (I think on the sendmail.php page itself)

My question is: I want the output message appear on the same place where the user enters their information. I dont want a completely blank page to show the output message.

My php code is:

<?

$to = “[email protected]“;
$subject = “Program Hakk&#305;nda Yorum”;
$name = $_REQUEST[‘name’] ;
$age = $_
REQUEST[‘age’] ;
$sex = $_REQUEST[‘sex’] ;

$body = $_REQUEST[‘id1’] . $_REQUEST[‘id2’] . $_REQUEST[‘comment’] . $_REQUEST[‘age’] . $_REQUEST[‘sex’] ;

$headers = “From: $name”;

$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo “success”; }
else
{echo “failure”; }

?>

I know this is a starter question, I am just learning php and I appreciate any help. Thanks…

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 06.2009 — You would need to add the form and the mail php code to the same script and have the form post to itself:

[code=php]<?php

$to = "[email protected]";
$subject = "Program Hakk&#305;nda Yorum";

// you should consider cleaning this input, especially if you are sending html mail
$name = $_REQUEST['name'] ;
$age = $_REQUEST['age'] ;
$sex = $_REQUEST['sex'] ;

$body = $_REQUEST['id1'] . $_REQUEST['id2'] . $_REQUEST['comment'] . $_REQUEST['age'] . $_REQUEST['sex'] ;

$headers = "From: $name";

$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "success"; }
else
{echo "failure"; }

?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<!-- form parts here -->
</form>
[/code]
Copy linkTweet thisAlerts:
@SyCoJan 06.2009 — You can user header() to move people to different pages without user interaction.

It's easier to do it all on the same page as you can check for errors and reload filled in inputs with minimal hassle. You do however get issues with reloading the page and the resend message. Using a separate page to process the form fixes that but you need to post the values back to the form page to propagate the fields. cURL works great for that and is not to tricky once you get your head round it. cURL is not always available on shared hosting though, so you can use this method too.

http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
×

Success!

Help @mrr00 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...