Search code examples
phpapacheemailapache-config

PHP mail() function does not work on web-host


I'm having issues sending emails using the php mail() function. I know the php script I have works because I have an identical copy of it on another web-hosting company and it works there.

I think it has to do with the web-hosting company itself. Do any of you know what I need to do in order to make it work? Is there something I need to tell them to install? I think they're running on Apache.

Thanks, Amit

For clarification purposes, here is the mail-script.

<?php

$to = 'my@email.com';
$subject = 'Contact from your website';

$message = 
'Below are details from the Contact Us Form ' . "\n\n" . 
'Name: ' . $_REQUEST['name'] . "\n\n" . 
'Telephone Number: ' . $_REQUEST['phone'] . "\n\n" . 
'E-mail address: ' . $_REQUEST['email'] . "\n\n" . 
'Comments: ' . $_REQUEST['comments'];

$email = $_REQUEST['email'];
$headers = 'From: ' . $email . "\r\n" .
            'Reply-To: ' . $email . "\r\n" .
          'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=ISO-8859-1";       

//SPAM CHECK
$str = $_REQUEST['spam'];
$strE = $_REQUEST['email'];

if( $str != "10" || $strE == "")
{
    echo "<div align='center' style='color:red'>One or more of the form fields were incorrect, you will be redirected to the contact page within 3 seconds.</div>";
?><meta http-equiv="refresh" content="3;URL=http://engineercreativity.com/samples/biz/contact"><!-- EDIT THIS -->

<?php   
} else {
    mail ($to, $subject, $message, $headers);
?>
<meta http-equiv="refresh" content="0;URL=http://engineercreativity.com/thankyou.html"> <!-- EDIT THIS AS WELL -->
<!--
<div class="text" align="center" style="text-align: center; color: green;">
<br/>
Thank you for contacting us!
<br/>
The message was succesfully sent!
</div>
-->
<?php
} 
?> 

Solution

  • If it is a dedicated server, make sure you have postFix Mail installed (http://www.postfix.org/)

    I faced this error today itself as the SMTP server was not available (i assumed it as there by default, but not)