[web] PHP and Mail

Recommended Posts

I'm rather new to web programming, and am creating my own site, so I'm trying to get a handle on PHP. As I already know C++, the syntax hasn't been terribly hard to learn. I have created an html/php feedback form, partially stolen from a tutorial, and it doesn't seem to work. No matter what I enter, it always returns "There was a problem sending the mail. Please check that you filled in the form correctly." Here's the code: feedback.html
<html>

<form action="mail.php" method="post">
E-mail: <input type="text" name = "email"><br><br>
<textarea name="comments" rows="10" cols="50">Thank you for visiting the site. We would appreciate it if you would leave some comments in this box to help us improve.</textarea>
<br><input type="submit" value="Submit">
</form>

</html>
mail.php
<?
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$to="jacobdickinson@cox.net";$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email"; if(mail($to,"Comments From Your Site",$message,"From:$email\n")) {
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
does anyone know what could be causing this?

Share on other sites
Hmmm... the mail function has dependancies that need to be setup. This is straight from the php.net docs:

For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.

I hope that helps.

Share on other sites
if(!isset($_POST['name']) && !isset($_POST['comments']) && !isset($_POST['email']))... 2. Some mail sending implementations require a \r\n in the headers (i.e. "From:$from\r\n")

3. Get rid of the space in this tag:
<input type="text" name = "email">

Apart from that, I can only assume it's a problem with your configuration. PHP normally throws up error messages when it fails to send an email for whatever reason (you silence it by putting a @ in front of the function), but it hasn't here.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628294
• Total Posts
2981882

• 9
• 9
• 11
• 10
• 10