Forum Moderators: coopster

Message Too Old, No Replies

Help with email form

         

adammc

9:55 am on Oct 24, 2006 (gmt 0)

10+ Year Member



Hi Guys,

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 &amp; 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.

adammc

10:34 am on Oct 24, 2006 (gmt 0)

10+ Year Member



I have worked it out, thanks anyway.

For some reason, my clients host wanted me to declare al the variables again, after the error checking.

example:

[php]
$name = $_POST['name'];
$to= ......
[/php]

dreamcatcher

2:44 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi adammc,

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]

phparion

6:48 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think, it is good practice to use superglobar arrays to fetch variables for use if you know that your code will be used on different servers.

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.