Sign in to follow this  
NewbJ

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

<head>
<title>Your Comments</title>
<head>

<form action="mail.php" method="post">
Your Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br><br>
Comments<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")) {
echo "Thanks for your comments.";
} 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 this post


Link to post
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 this post


Link to post
Share on other sites
1. Check your inputs!
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.

Share this post


Link to post
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

Sign in to follow this