I’m trying to use a simple PHP mail() function to create user feedback from a website. I’m using the ‘PHP Secure E-mail’ sample script from W3 as a basis. Because of the nature of the email, there’s no need for added security or using some of the libraries, e.g. swift mailer, that have been suggested in other posts related to this topic.
When the base form is loaded and the ‘send mail’ button selected, I get a “server error” message and the following supporting information:
“The website encountered an error while retrieving
http://www.examplewebsite/formsuccessful.php?forename=Joe&surname=Blogs&email=j.oe.blogs%40example.co.uk&subject=TEST+2&message=Test+Content
It may be down for maintenance or configured incorrectly.”
The file ‘formsuccessful.php’ file is definitely on the server in the correct folder – unless there’s another setting I’m overlooking to enable to this type of PHP scripting?
I’ve included both the form and PHP code below in case there’s an error in those.
Would certainly appreciate some help, I’ve danced around the houses on this one that many times I can’t see the wood from the trees any more.
Cheers.
PHP:
<?php
function spamcheck($field)
{
$field1=filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var($field1, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['email']))
{
$mail = $_REQUEST['email'];
$mailcheck = spamcheck($mail);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$name = $_REQUEST['forename']." ".$_REQUEST['surname'];
mail("admin@examplewebsite.com", "Subject: "$subject,
"Message: "$message, "From: "$email," ",$name );
}
}
else{
//reload page with message highlighting error
}
?>
HTML Form:
<form method="REQUEST" action="formsuccessful.php">
<fieldset class="master">
<legend class="master" style="text-align:left;"><b><u>Personal Details:</u></b></legend>
<ol class="master">
<li class="master"><label class="master" for"forname">Forename<em class="master">*</em></label><input class="left" type="text" name="forename" size="30" /></li>
<li class="master"><label class="master" for"surname">Surname<em class="master">*</em></label><input type="text" name="surname" size="30" /></li>
<li class="master"><label class="master" for"email">Your Email<em class="master">*</em></label><input type="text" name="email" size="30" /></li>
</ol>
<legend class="master" style="text-align: left;"><b><u>Email Contents:</u></b></legend>
<ol class="master">
<li class="master"><label class="master" for="subject">Subject:<em class="master">*</em></label><input type="text" name="subject" size="30" /></li>
<li class="master"><label class="master" for="message">Content:<em class="master">*</em></label><textarea cols="50%" rows="20" onkeyup="checkContent()" name="message" id="message"></textarea></li>
<li class="master"><input type="submit" value="Send Email" /></li></ol>
</fieldset>
</form>
Standing by to have the criminally obvious pointed out to me.
You seem to have some errors here:
If you want to concatenate, you need to use something like:
You also have one parameter too many, I’m not sure what you want to do with the last part
," ", $namebut that’s not valid input for the last parameter, see the manual formail.