Copy link to clipboard
Copied
Dear Forums Users,
I have an online contact form set up on a website where all the fields are required or else the form doesn't get sent as I've used Spry Validation fields in Dreamweaver CS5 on mac. The problem I'm having is when I send a message using this online contact form, I receive the submission in my email inbox as expected, but the message is an attachement and when opened it is BLANK! This is the main problem, that it's showing as blank, the second is that it's appearing in the email as an attachment and not as normal text with the rest of the email.
Please can someone with obviously more experience and wisdom than I please tell me what I'm doing wrong and how I can fix this.
Below is the code I have used for the "mailer.php". (Obviously I have omitted the real email address for obvious reasons here.)
<?PHP
$to = "sample@anemailaddresshere.com";
$subject = "Online Contact Form Message";
$headers = "From: Your Web Site Name here";
$forward = 1;
$location = "thankyou.html";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "You have received a message through your Online Contact Form. Please find below the message details. It was submitted on $date at $time.\n\n";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
Thanking you in advance for your time, advice and help.
Copy link to clipboard
Copied
Let see your form code. Did you specify an enctype?
Copy link to clipboard
Copied
No, I haven't got an enctype on it actually, should there be one? and if so which one?
Here is the form code :
<form id="form1" name="form1" method="post" action="/mailer.php">
<input type="hidden" name="redirect" value="thankyou.html" />
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="258" class="contactCellAlign"><span id="sprytextfield1"><span class="textfieldRequiredMsg">A value is require</span></span><p class="contactformHeadings">Full name</p></td>
<td width="342" class="contactCellAlign"><span id="sprytextfield6">
<label for="fullname2"></label>
<input name="full_name" type="text" id="fullname2" size="45" />
<span class="textfieldRequiredMsg">Please enter your full name. (First and Last names)</span></span></td>
</tr>
<tr>
<td class="contactCellAlign"><p class="contactformHeadings">Job title</p></td>
<td class="contactCellAlign"><span id="sprytextfield2">
<label for="jobtitle"></label>
<input name="job_title" type="text" id="jobtitle" size="45" />
<span class="textfieldRequiredMsg">Please enter your job title.</span></span></td>
</tr>
<tr>
<td class="contactCellAlign"><p class="contactformHeadings">Company name</p></td>
<td class="contactCellAlign"><span id="sprytextfield3">
<label for="companyname"></label>
<input name="company_name" type="text" id="companyname" size="45" />
<span class="textfieldRequiredMsg">Please enter your company name.</span></span></td>
</tr>
<tr>
<td class="contactCellAlign"><p class="contactformHeadings">Telephone number</p></td>
<td class="contactCellAlign"><span id="sprytextfield4">
<label for="telephone"></label>
<input name="telephone_number" type="text" id="telephone" size="45" />
<span class="textfieldRequiredMsg">Please enter your telephone number.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td class="contactCellAlign"><p class="contactformHeadings">Email address</p></td>
<td class="contactCellAlign"><span id="sprytextfield5">
<label for="emailaddress"></label>
<input name="email_address" type="text" id="emailaddress" size="45" />
<span class="textfieldRequiredMsg">Please enter your email address.</span></span></td>
</tr>
<tr>
<td class="contactCellAlign"><p class="contactformHeadings">Reason for contacting<br />
Cyber Investigations N.I. Ltd.</p></td>
<td class="contactCellAlign">
<span id="spryselect2">
<label for="reason_for_contacting"></label>
<select name="reason_for_contacting" id="reason_for_contacting">
<option value="-1" selected="selected">Please select one</option>
<option>I am interested in your SECURITY services</option>
<option>I am interested in your INVESTIGATIONS services</option>
<option>I am interested in your TESTING services</option>
<option>I am interested in your EDUCATION services</option>
<option>I am interested in your SOCIAL ENGINEERING services</option>
<option>I am interested in your COMPLIANCE services</option>
<option>I would like to talk about something else</option>
</select>
<span class="selectInvalidMsg"><br />
Please select a reason from the list.</span></span></p></td>
</tr>
<tr>
<td class="contactCellAlign"><p class="contactformHeadings">Message</p></td>
<td class="contactCellAlign"><span id="sprytextarea1">
<label for="messagecontent"></label>
<textarea name="message_content" id="messagecontent" cols="40" rows="15"></textarea>
<span class="textareaRequiredMsg"><br />
Please enter your message.</span></span></td>
</tr>
<tr>
<td colspan="2" class="buttonCellAlign"><p>
<input name="sendbutton" type="submit" class="customeButton" id="sendbutton" value="Send" />
</p></td>
</tr>
</table>
</form>
Thank you for your help
Copy link to clipboard
Copied
No, you shouldn't need an enctype. I'm not sure if it matters and I seriously doubt that it does(I'm not a php developer), but your form method is set to lower case 'post' but the PHP script is checking for upper case. What is the doctype of the page set to?
I would suggest setting the forward flag to 0 and then put some echo statements in the loops to see where the execution is going.
Copy link to clipboard
Copied
bregent wrote:
(I'm not a php developer)
Me neither!
bregent wrote:
What is the doctype of the page set to?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
bregent wrote:
I would suggest setting the forward flag to 0 and then put some echo statements in the loops to see where the execution is going.
As I am not a PHP developer, I am just trying to find my way through and don't fully understand everything. How would I go about adding some "echo statements in the loops" ? and what exactly does it mean?
Sorry for my ignorance, but I really need help with this. Some emails are are getting through to my client but some are appearing blank. I'm stuck!!
Copy link to clipboard
Copied
Well I'll try to fumble my way through it.
First change
$forward = 1;
to
$forward = 0;
Then change:
******************************************************
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
*******************************************************
To:
if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo "POST LOOP";
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
echo "Form Field Read";
}
echo $msg;
}
Run it and send post the results.