tags:

views:

44

answers:

4

Hi,

I have a script for sending an email from a form on a website. I know the code is fine - I've previously tested with two different hosting companies. This time I'm using it on a an actual server, as opposed to a hosting company. Basically the user fills in the form, clicks submit and gets the confirmation page that the message has been sent. The only thing is no email comes. Here is the script:

 $nickname = $_REQUEST['nickname'] ;
  $email = $_REQUEST['email'] ;
  $tel = $_REQUEST['tel'] ;
      $comp = $_REQUEST['comp'] ;
  $message = $_REQUEST['message'] ;


// Let's check if all fields are filled in!
if(empty($nickname) || empty($email) || empty($comp))
{
$error = "All of the required fields have not been completed, <a href=\"javascript:history.go(-1)\">please click here to go back.</a>";
}
else
{
$content= "$nickname has sent you an e-mail from XXX
Query:
$message
You can contact $nickname via Email: $email. <br />Other relevant details of individual: <br />Telephone Number: $tel <br />Company: $comp";

mail( "[email protected]", "Query", $content, "From: $email"); //first thing has to be address it is going to, then what the subject of the mail should be, the content and a from address which will be the query submitter.
echo  "<h2>$nickname</h2><br></br>
    Your query has been succesfully sent. <br></br><br></br>
    We will deal with this query and be in touch as soon as possible.<br></br><br></br><br></br> 
    The contact details you submitted are: <br></br><br></br>
    <strong>Email:</strong>&nbsp; $email<br></br><br></br>
    <strong>Phone:</strong>&nbsp; $tel<br></br><br></br>
    <strong>Company:</strong>&nbsp; $comp<br></br><br></br>
    <a //href=\"javascript:history.go(-1)\"> Click here to return to the contact page.</a></br>";
}; 

?>

I don't know if this matters either but up until recently, PHP would not work on the server, and gave a HTTP error 405 error saying the verb was not allowed. This has since been resolved.

+1  A: 

The PHP script is not even suppose to send the email, a mail server like sendmail, qmail or postfix does that. Check if they are configured well.

Elzo Valugi
+1  A: 

Most likely your server doesn't have an MTA (mail transfer agent) installed. PHP's mail() function doesn't send the email itself, it passes the result to the system's default MTA.

Quick question - are you using a Windows-based server? Unix/Linux servers almost always have an MTA in their default setup (usually sendmail or exim or some such), but Windows servers generally don't; you have to install one yourself.

Spudley
+1  A: 

Hi,

as Elzo already said the mail functionality is dependent on having a mail server set up and configured properly on your server. Have a look at http://www.php.net/manual/en/book.mail.php for configuration options for setting up mail server access in php.

mail() itself is only a wrapper for the underlying functionality.

If you don't have administrator access the runtime configuration variables can be very useful:

<?php 
ini_set("SMTP","smtp.example.com" ); 
ini_set('sendmail_from', '[email protected]'); 
?> 

The sendmail_path variable needs to be set in the system configuration file like this:

sendmail_path = /usr/sbin/sendmail -t -i

If you want better error reporting and support for exceptions with informative messages when somethings goes wrong you should take a look at phpmailer http://phpmailer.worxware.com/

It gives you a fairly nice object oriented interface to sending emails with good and informative error reporting.

thomasmalt
+1  A: 

Congratulations. You've created an open SPAM service that allows everyone to send mass-mails.

Check this out:

http://www.securephpwiki.com/index.php/Email_Injection#php_mail.28.29_function

:-)

Jan.