Configure contact form on live server using php

I need to adjust the settings of a contact form so that the format of the message that a AJAX/PHP script presents to the SMTP service works.

The critical part is the ‘From field’ it needs to show ‘noreply@domain.org’

The message should output :

-----Original Message-----
From: noreply@domain.org [mailto:noreply@domain.org]
Sent: 01 March 2013 11:46
To: $name
Subject: $message.

The format of the message presents to the SMTP service is important.

My currrent php mail process script is;


<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include dirname(dirname(__FILE__)).'/config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{
include 'functions.php';

$headers = 'From: name <noreply@domain.org>' .

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
//$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);

$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}

// Check message (length)

if(!$message || strlen($message) < 15)
{
$error .= "Please enter your message. It should have at least 15 characters.<br />";
}

if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, "$headers",
     "From: ".$name." <".$email.">\\r\
"
    ."Reply-To: ".$email."\\r\
"
    ."Message: ".$message."\\r\
");

if($mail)
{
echo 'OK';
} 

}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}

}
?>

you have them in the wrong order it seems:


$subject = "This is not spam, please read this email";

$mail = mail(WEBMASTER_EMAIL
     , $subject,
     "From: ".$name." <".$email.">\\r\
" ."Reply-To: ".$email."\\r\
"  ."Message: ".$message."\\r\
"
    , $headers);

… by the looks of things …

Okay i’m fine on this yet how will it address my issue in making sure that the noreply@domain.org is entered into the From field to allow the SMTP to process?

Current code is now -

<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/

include dirname(dirname(__FILE__)).'/config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{
include 'functions.php';

$headers = 'From: CYPSP Website <noreply@domain.org>' .
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
//$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);

$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.<br />';
}

// Check message (length)

if(!$message || strlen($message) < 15)
{
$error .= "Please enter your message. It should have at least 15 characters.<br />";
}

if(!$error)
{
$subject = "This is not spam, please read this email";

$mail = mail(WEBMASTER_EMAIL, "$subject",
     "From: ".$name." <".$email.">\\r\
"
     ."Reply-To: ".$email."\\r\
"  
     ."Message: ".$message."\\r\
"
     , $headers);  

if($mail)
{
echo 'OK';
} 

}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}

}
?>