HI
I am trying to send a mail from a html form. I am working with a localhost. I can't send the email but it doesn't show the error. What can I do to see the error? Thank you for your time.

<?php
if ($_POST['submit'])
{ 	$nume=$_POST['nume_exp'];
	$mesaj=$_POST['mesaj'];
	
if ($nume && $mesaj)
		{error_reporting(E_ALL); 
		ini_set('display_errors', true);
		$to = 'cristina.horjea@yahoo.com';                 // Adresa unde va fi trimis mesajul 
    $subiect = 'Mesaj de pe site'; 
    $mesaj = $_POST['mesaj']; 
    $from = 'From: '. $_POST['mail_exp']; 
		
		if (@mail($to, $subiect, $mesaj, $from))
			 { echo 'Mesajul a fost trimis cu succes.'; 
    		} 
    	else {  echo 'Eroare, mesajul nu a putut fi expediat.'; }
		
		}
else die("Nu ati introdus valori in toate campurile");
		
		
		
}



?>
<form method="post" action="contact.php">
	 <table>
			<tr>
				<td>NUME:</td>
				<td><input type="text" name="nume_exp" size="25"></td>
			</tr>
			<tr>
				<td>PRENUME:</td>
				<td><input type="text" name="prenume_exp" size="25"></td>
			</tr>
			<tr>
				<td>ADRESA EMAIL:</td>
				<td><input type="text" name="mail_exp" size="25"></td>
			</tr>
			<tr>
				<td>MESAJ:</td>
				<td><textarea name="mesaj" cols="25" rows="8"></textarea></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="reset" value="Anuleaza"/>
					<input type="submit" name="submit" value="Trimite"/>
				</td>
			</tr>
		</table>
</form>

It is possible you have not specified a email from which it can be sent, check php.ini at the section of mail options. This problem does not occur on servers, because on most servers the server also has a mail-server.

~G

just to remind you... you cant directly use the php mail function without first having an installed and working email system

Member Avatar for rajarajan2017

Your if..else statements shows the message that you have. If you want to see the actual error message leave the else part (or) remove the condition and execute it directly then you will see the warning or error messages.

I found out that mail() function did not work on some web hosting provider. I don't know why, but I experienced it couple of years ago.

I use PHPMailer class till now. It rocks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.