Jump to content
  • Advertisement
Sign in to follow this  

[web] PHP and Mail

This topic is 5413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

<title>Your Comments</title>

<form action="mail.php" method="post">
Your Name: <input type="text" name="name"><br>
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">

$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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!