Richard Cousins
03-25-2011, 04:33 PM
Hi there, Ive set up a contact form on my website and so that some one can ask me a question and it will be sent to my e-mail address.
Ive checked the e-mail address I am using and its set up to send and receive e-mails and Ive tested this.
The php form seem to work as expected as well, i submit and it refreshes to the homepage and I get no errors, but once this has happened the e-mail never arrived to my e-mail account.
My question is why is this? I'm stumped.
The code im using is this:
PHP
<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Contact form';
// Your email address. This is where the form information will be sent.
$emailadd = 'me@richardcousins.net';
// Where to redirect after form is processed.
$url = 'http://www.richardcousins.net/';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
The HTML/FORM
<form action="sendresults.php" method="post" name="ContactForm">
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your full name" />
<label for="email">Email:</label>
<input type="text" id="email" name="email" placeholder="Enter your email address" />
<label for="message">Message:</label>
<textarea id="comments" name="comments" placeholder="What's on your mind?"></textarea>
<input type="submit" name="Submit" value="Submit" />
</fieldset>
</form>
Maybe im stupid but im sure PHP is on the servers and part of the hosting plans with godaddy right? They host my site and e-mail address.
Many Thanks if you can help
Ive checked the e-mail address I am using and its set up to send and receive e-mails and Ive tested this.
The php form seem to work as expected as well, i submit and it refreshes to the homepage and I get no errors, but once this has happened the e-mail never arrived to my e-mail account.
My question is why is this? I'm stumped.
The code im using is this:
PHP
<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Contact form';
// Your email address. This is where the form information will be sent.
$emailadd = 'me@richardcousins.net';
// Where to redirect after form is processed.
$url = 'http://www.richardcousins.net/';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
The HTML/FORM
<form action="sendresults.php" method="post" name="ContactForm">
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your full name" />
<label for="email">Email:</label>
<input type="text" id="email" name="email" placeholder="Enter your email address" />
<label for="message">Message:</label>
<textarea id="comments" name="comments" placeholder="What's on your mind?"></textarea>
<input type="submit" name="Submit" value="Submit" />
</fieldset>
</form>
Maybe im stupid but im sure PHP is on the servers and part of the hosting plans with godaddy right? They host my site and e-mail address.
Many Thanks if you can help