Php contact us email sent but not received


$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$website = $_POST['website'];
$mess = $_POST['message'];
$frm = str_replace(" ","",$name);

$to = "< email address redacted >, < email address redacted >"; 
$subject = "Enquire Generation";

$message  = '<html><body>';
$message .= '<h4>Name: '.$name.'</h4>';
$message .= '<h4>Contact No.: '.$contact.'</h4>';
$message .= '<h4>Email: '.$email.'</h4>';
$message .= '<h4>Website: '.$website.'</h4>';
$message .= '<h4>Message: '.$mess.'</h4>';
$message .= '</body></html>';

$headers = "From:".$frm. "\r\n";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

if (mail($to, $subject, $message, $headers)) {
header("Location: thankyou.php");
else {
header("Location: mailFailed.php");


Hi there,
A couple of common things to check for:

  • look in the spam or bin folder
  • the email address specified in the ‘from’ address has a different domain than the website server domain where the email is being sent from. This is a security measure email clients implement to avoid phising or spam emails.
    Actually I can’t see you’re specfying the sender email? That might be the problem.

Hope that helps

Thanks for reply

how to resolve issue

class Mail {
    private $smtpServer = '';
    private $port = '25';
    private $timeout = '45';
    private $username = '< email address redacted >';
    private $password = '< password redacted >';
    private $newline = "\r\n";
    private $localdomain = '';
    private $charset = 'UTF-8';
    private $contentTransferEncoding = false;

    // Do not change anything below
    private $smtpConnect = false;
    private $to = false;
    private $subject = false;
    private $message = false;
    private $headers = false;
    private $logArray = array(); // Array response message for debug
    private $Error = '';

    public function __construct($to, $subject, $message) {
        $this->to = &$to;
        $this->subject = &$subject;
        $this->message = &$message;
        // Connect to server
        if(!$this->Connect2Server()) {
        	// Display error message
            echo $this->Error.$this->newline.'<!-- '.$this->newline;
            echo $this->newline.'-->'.$this->newline;
            return false;
        return true;

    private function Connect2Server() {
        // Connect to server
        $this->smtpConnect = fsockopen($this->smtpServer,$this->port,$errno,$error,$this->timeout);
        $this->logArray['CONNECT_RESPONSE'] = $this->readResponse();

        if (!is_resource($this->smtpConnect)) {
            return false;
        $this->logArray['connection'] = "Connection accepted: ".$this->readResponse();
        // Hi, server!
        $this->sendCommand("EHLO $this->localdomain");
        $this->logArray['EHLO'] = $this->readResponse();
        // Let's know each other
        $this->sendCommand('AUTH LOGIN');
        $this->logArray['AUTH_REQUEST'] = $this->readResponse();
        // My name...
        $this->logArray['REQUEST_USER'] = $this->readResponse();
        // My password..
        $this->logArray['REQUEST_PASSWD'] = $this->readResponse();
        // If error in response auth...
        if (substr($this->logArray['REQUEST_PASSWD'],0,3)!='235') {
            $this->Error .= 'Authorization error! '.$this->logArray['REQUEST_PASSWD'].$this->newline;
            return false;
        // "From" mail...
        $this->sendCommand("MAIL FROM: $this->username");
        $this->logArray['MAIL_FROM_RESPONSE'] = $this->readResponse();
        if (substr($this->logArray['MAIL_FROM_RESPONSE'],0,3)!='250') {
            $this->Error .= 'Mistake in sender\'s address! '.$this->logArray['MAIL_FROM_RESPONSE'].$this->newline;
            return false;
        // "To" address
        $this->sendCommand("RCPT TO: $this->to");
        $this->logArray['RCPT_TO_RESPONCE'] = $this->readResponse();
        if (substr($this->logArray['RCPT_TO_RESPONCE'],0,3)!='250') {
            $this->Error .= 'Mistake in reciepent address! '.$this->logArray['RCPT_TO_RESPONCE'].$this->newline;
        // Send data to server
        $this->logArray['DATA_RESPONSE'] = $this->readResponse();
        // Send mail message
        if (!$this->sendMail()) return false;
        // Good bye server! =)
        $this->logArray['QUIT_RESPONSE'] = $this->readResponse();
        // Close smtp connect 
        return true;
    // Function send mail
    private function sendMail() {
        $this->logArray['SEND_DATA_RESPONSE'] = $this->readResponse();
        if(substr($this->logArray['SEND_DATA_RESPONSE'],0,3)!='250') {
            $this->Error .= 'Mistake in sending data! '.$this->logArray['SEND_DATA_RESPONSE'].$this->newline;
            return false;
        return true;
    // Function read response
    private function readResponse() {
        while($str = fgets($this->smtpConnect,4096))
            $data .= $str;
            if(substr($str,3,1) == " ") { break; }
        return $data;
    // function send command to server
    private function sendCommand($string) {
        return ;
    // function send headers
    private function sendHeaders() {
        $this->sendCommand("Date: ".date("D, j M Y G:i:s")." +0700");
        $this->sendCommand("From: <$this->username>");
        $this->sendCommand("Reply-To: <$this->username>");
        $this->sendCommand("To: <$this->to>");
        $this->sendCommand("Subject: $this->subject");
        $this->sendCommand("MIME-Version: 1.0");
        $this->sendCommand("Content-Type: text/html; charset=$this->charset");
        if ($this->contentTransferEncoding) $this->sendCommand("Content-Transfer-Encoding: $this->contentTransferEncoding");
        return ;

    public function __destruct() {
        if (is_resource($this->smtpConnect)) fclose($this->smtpConnect);

how to resolve it

I’m not really sure what’s the problem as I’m unfamiliar with the code.
Check that the property $this->username contains a valid email address which matches the domain address that contact form is in.
So if the domain name is the email address of the sender should be something like

I would suggest using a popular free library called PHPMailer to send your email if that’s possible because it’s free, has SMTP support and deals with all the problems in a simple way.
Here’s an example:

Thanks Andres

i am using for same email id for related domain like ( but not working

Are you using the code you posted in both post #1 and post #3? I don’t see how the two sets of code relate to one another.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.