Forum Moderators: coopster
I have just had a strange problem occur. The code shown below send the email correctly on my host, on my clients server, no email is sent?
Can anyone possibly help me with this as I am REALLY stumped:
[php]
<?php
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
// get email variables from config file
include ('config.php');
$message = nl2br($message);
// Initialize error array.
$errors = array();
// Check the name field has been filled in.
if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';
}
// Check for an email address & make sure there are no errors.
if (empty($_POST['from'])) {
if (!eregi("^.+@.+\\..+$", $from)){
$errors[] = 'Your email address contains errors.';
}
} else
$from=trim($from);
// Check to make sure of a valid referer for the email form
if($verify_referrer==1)
{
if(!eregi("$domain", $HTTP_REFERER) &&!eregi("$domainAlias", $HTTP_REFERER))
{
$errors[] ="Invalid referer.";
}
}
// Check the description field has been filled in.
if (empty($_POST['message'])) {
$errors[] = 'The message field was empty.';
}
// Check the description field containes no more than the Max chars defined in the config file
if (strlen($message) >= $maxSize)
{
$errors[] = "Your message is too long. The maximum characters allowed is $maxSize. ";
}
// If everything went okay - send the email
if (empty($errors)) {
$body="$message<br /><br /><br />--------------------------<br />Sent by: $name - $from<br />Phone: $phone<br />--------------------------";
$from="\"$name\" <$from>\n";
$headers="Content-Type: text/html; charset=Windows-1252\n";
$headers.="From: $from \n";
mail($to,$subject,$body,$headers);
echo("<p align=\"left\"><font class=\"maintext\">Thank you for your email $name.<br />Your business is important to us & we will be in touch as soon as possible.</font></p><br /><br /><br /><br /><br /><br />");
} else { // Report the errors.
echo "<font class=maintext><h1 id=mainhead>Error!</h1>
<p class=\"error\">The following error(s) occurred:<br />";
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please go back and try again.</p><p><br /></p>';
} // End of if (empty($errors)) IF.
} else { // If form hasnt been submitted - Display the email form.
?>
[/php]
** The $to variable is set in the config file and has been unchanged during the process of changing the server.
They probably have register globals [uk.php.net] OFF, in which case you need to use the superglobal arrays.
Glad you got it sorted out.
dc
[edited by: dreamcatcher at 7:12 pm (utc) on Oct. 27, 2006]
and also you may want to read www.php.net/ini_set function that can be handy when you want to change the server php.ini settings according to your needs for your script's lifetime.