Jump to content

Send e-mail with PHP form... what can be wrong?


Actress
 Share

Recommended Posts

Hi!I used to use html pages with forms and when I hit the submit button it would post the data to PHP that would send the data by mail.But now I need to put the form in a PHP page, and I'm having trouble on making the mail code. I think it should work, but it doesn't... :) I can't figure out what's wrong here... can you help me?

			<?phpif (isset ($_POST['submit'])) {  //these are my variables... checked them lots of times, they are correct		  $name = $_POST['nome'];		  $phone = $_POST['telefone'];		  $details = $_POST['detalhes'];		  $date = $_POST['data'];		  $mail = $_POST['email'];//this is just to make sure they fill out all the important fieldsif ($name == "" || $phone == "" || $date == "" || $mail == "")	{//message asking to fill out all fields	echo "Por favor preencha todos os campos marcados com *";	} 	else {		$recipient = "Life Club <geral@tntvoip.pt>";		$subject = "Reserva";		$mail = $_POST['email'];		$msg .= "\n-------------------------------------------\n\n";		$msg .= "Reserva em nome de: ";		$msg .= $name;		$msg .= "\nTelefone: ";		$msg .= $phone;		$msg .= "\nDetalhes: ";		$msg .= $details;		$msg .= "\nData de reserva: ";		$msg .= $date;		$msg .= "\nE-mail: ";		$msg .= $mail;		$mailheaders = "De: $mail";		$success = mail("$recipient", "$subject", "$msg", "$mailheaders");			if ($success)				{//message stating the e-mail was sent				echo "E-mail enviado com sucesso. Obrigado.";				}					else						{//message stating the e-mail was not sent						echo "E-mail não enviado correctamente. Por favor tente de novo.";						}	}	}?>

Link to comment
Share on other sites

The first thing I see, which is a little funny, is you are trying to use a header called "De". The headers were written by English-speakers, so the header you are looking for is "From". It took me a while of looking at that to realize that 'de' is the Spanish equivalent.The other things, which won't affect if the mail gets sent or not, is that you re-define $mail in your else statement after you have it set already, and your call to the mail function does not need quotes around all the variables:mail($recipient, $subject, $msg, $mailheaders);

Link to comment
Share on other sites

The first thing I see, which is a little funny, is you are trying to use a header called "De". The headers were written by English-speakers, so the header you are looking for is "From". It took me a while of looking at that to realize that 'de' is the Spanish equivalent.The other things, which won't affect if the mail gets sent or not, is that you re-define $mail in your else statement after you have it set already, and your call to the mail function does not need quotes around all the variables:mail($recipient, $subject, $msg, $mailheaders);
Well, it has to be something else... I made all those changes and still doesn't work... :) I'm searching for all kinds of tutorials, they all do the "html form - php mail send" solution... I'm losing my sleep here and I'm sure it's a small little detail that I missed... :) Please anyone help...
Link to comment
Share on other sites

You say you used to use HTML pages to build a form which POSTed to a PHP page. Now you need the HTML page to be a PHP page? Can't you use the HTML code and simply rename the file .php rather than .html?If not, perhaps you could post your code for the PHP page where the user inputs the information?

Link to comment
Share on other sites

Are you seeing this message?"E-mail não enviado correctamente. Por favor tente de novo."
No... Nothing happens at all...
Have you confirmed that your Hosting service allows php? And allows the mail function?Some Hosts disabled the SMTP and POP3, so run a phpinfo to see.Just checking.
It allows PHP because I already did one thing in PHP once and it worked perfectly.
Link to comment
Share on other sites

OK, I re-formatted your code and added some debugging statements and turned on error reporting. Run this and see what it says:

<?phpini_set("display_errors", 1);error_reporting(E_ALL);if (isset ($_POST['submit'])){  echo "\$_POST['submit'] is set<br>";  //these are my variables... checked them lots of times, they are correct  $name = $_POST['nome'];  $phone = $_POST['telefone'];  $details = $_POST['detalhes'];  $date = $_POST['data'];  $mail = $_POST['email'];  //this is just to make sure they fill out all the important fields  if ($name == "" || $phone == "" || $date == "" || $mail == "")  {	//message asking to fill out all fields	echo "Por favor preencha todos os campos marcados com *";  }  else  {	$recipient = "Life Club <geral@tntvoip.pt>";	$subject = "Reserva";	$mail = $_POST['email'];	$msg .= "\n-------------------------------------------\n\n";	$msg .= "Reserva em nome de: ";	$msg .= $name;	$msg .= "\nTelefone: ";	$msg .= $phone;	$msg .= "\nDetalhes: ";	$msg .= $details;	$msg .= "\nData de reserva: ";	$msg .= $date;	$msg .= "\nE-mail: ";	$msg .= $mail;	$mailheaders = "From: $mail";	echo "sending mail...<br>";	if (mail($recipient, $subject, $msg, $mailheaders))	{	  //message stating the e-mail was sent	  echo "E-mail enviado com sucesso. Obrigado.";	}	else	{	  //message stating the e-mail was not sent	  echo "E-mail não enviado correctamente. Por favor tente de novo.";	}  }}else{  echo "\$_POST['submit'] was not set";}?>

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...