Jump to content

Passing a value to an html label? Please help


Actress
 Share

Recommended Posts

Hi!I'm a newbie in PHP and I followed a tutorial to be able to send a simple "newsletter form" to be sent by e-mail through PHP. The form is in an html page, where PHP gets the data form, and it's working beautifully.But the thing is that when it sends the mail, it opens a new page with only the success message, browsing away from the index.html, that is where I have the newsletter form.So I added a label on the html form and tried to tell PHP to print the success message in the label. But as much as I try, I can't find a way to do that. Can anyone help?Somehow I get the feeling that this is piece of cake to you... :) Thanks for your time!

Link to comment
Share on other sites

What do you mean label? you mean subject or what?PHP mail() function should be setup as so:

  $message  = $_POST['message'];  $to       = "admin@rsbattlehelp.com";  $subject  = $_POST['category'] . " : ";  $subject .= $_POST['subject'];  $from     = $_POST['usrname'] . ", ";  $from    .= $_POST['email'];  $headers  = "from: " . $from;  //sending the mail  mail($to, $subject, $message, $headers);

You dont need to make it so it include everything I have but most of it if you want it to look nice.. hope this helps.

Link to comment
Share on other sites

I have this code working in perfect condition:

<?php// variáveis$Name = Trim($_POST[nnome]);$EmailFrom = Trim($_POST[nmail]); $EmailTo = "My name here <my e-mail here>";$Subject = "Newsletter";$Result = Trim($_POST[resultado]); //this was my poor attempt to "call" the label I have in my HTML page// validar$validationOK=true;if (Trim($Name)=="") $validationOK=false;if (Trim($EmailFrom)=="") $validationOK=false;if (!$validationOK) {  print $Result = "Erro ao enviar"; //here trying to print the error message to my HTML label  exit;}// este é o texto que vai estar no body do e-mail$Body .= "Adicionar à newsletter:\n";$Body .= "Nome: ";$Body .= $Name;$Body .= "\n";$Body .= "E-mail: ";$Body .= $EmailFrom;$Body .= "\n";// e-mail a enviar $success = mail($EmailTo, $Subject, $Body, "De: $Name <$EmailFrom>");// mensagem de sucesso ou nãoif ($success){print $Result = "Obrigado pelo registo";} //here trying to print the success message to my HTML label the same way as aboveelse{print $Result = "Erro ao enviar";} //here trying again to print the error message to my HTML label// enviar cópia de e-mail ao subscritormail("$Name <$EmailFrom>", "Sucesso", "O seu e-mail foi adicionado correctamente à nossa base de dados. Obrigado.", "De: My name <my e-mail>");?>

It sends the both e-mails already. Works fine that way.But I wanted to pass the error or success messages to my html label, instead of opening a new page.Is it possible?Thanks!

Link to comment
Share on other sites

So you are saying you want to stay on the same page (don't reload the page) and have a message show up? That's fairly difficult to do with something as complex as email. You could do some tricks through javascript, but if they had javascript turned off it wouldn't do anything.It's probably just easiest to send it to another page. You can always send it to the exact same page, only have a message in the label this time.

Link to comment
Share on other sites

That's fairly difficult to do
Oh, ok... This means I'm not so dumb as I thought... :)
You can always send it to the exact same page, only have a message in the label this time.
Ohhh I see what you mean... That's a good Idea! Thanks! :)
Link to comment
Share on other sites

So, that is what happens very often :) Some form on a page submits its data to itself, so it can directly add content to the very same form, if eg data is missing, incomplete, succesfully submitted, or whatever. Very handy isn't it :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...