Hello. I need your help with PHP.


I recently began studying it, and I am stuck at the "make a contact form" exercice.

I am trying to understand the concepts behind it. I think I get everything, but still my Form won't work.


I event went as far as to reproduce an example from the Internet, and it doesn't work either... I'm starting to think there is something wrong with my PHP installation.


Here is the HTML code for the form:

<html>
<body>
<form action="send_contact.php" method="post"> 
<table width="400" border="0" cellspacing="2" cellpadding="0"> 
<tr> 
<td width="29%" class="bodytext">Your name:</td> 
<td width="71%"><input name="name" type="text" id="name" size="32"></td> 
</tr> 
<tr> 
<td class="bodytext">Email address:</td> 
<td><input name="email" type="text" id="email" size="32"></td> 
</tr> 
<tr> 
<td class="bodytext">Comment:</td> 
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td> 
</tr> 
<tr> 
<td class="bodytext">&nbsp;</td> 
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td> 
</tr> 
</table> 
</form>
</body>
</html>

And here is the code for the php file (send_contact.php):

<?php 
$ToEmail = 'my@email.com'; 
$EmailSubject = 'Site contact form '; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>

I'm getting this error:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\send_contact.php on line 10

and then it says

Failure

whic means the code IS running to the end, but somehow it can't connect...

I'm using XAMMP for Apache.

Do I need to further tweak it?

Oh, and notice that I changed the code in $ToEmail to avoid posting my address on the internet, but I'm using my real address. It's gmail, by the way.

Thanks in advance

Recommended Answers

All 3 Replies

Just to see if you can use the mail() function, run this PHP:

<?php
if(mail("me@example.com", "hello", "hello")) { //replace me@example.com with your email

echo "Sent! Check your email to see if it went through";

}

else {

echo "ERROR";

}

?>

I get this:

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\Tests\tessst.php on line 2
ERROR

So, the mail() function is not working...

Nevermind I found the answer on my own:

The server has to have some email-sending software. In Linux I had to install sendmail to get it to work.

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.