Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Blank emails from PHP Spry Form

Posted on 2010-11-10
4
Medium Priority
?
525 Views
Last Modified: 2012-05-10
Hi,

On my website i have a PHP contact form with Spry Validation.
Even with the Spry Validation, i keep getting blank emails sent through from the form to my email.
Im not sure why this is happening, something server side i guess?
Could someone please help with this issue. The form and validation works fine when you enter in details as normal.
Please see the code for the PHP and HTML below.
<form action="enquiry-process.php" method="post" id="index-form">
<fieldset>
<legend>Enquiry</legend>

<div><span id="spry_name">
<input name="name" type="text" id="name" value="name" />
<span class="textfieldRequiredMsg">A value is required.</span></span></div>

<div><span id="spry_company">
<input name="company" type="text" id="company" value="company" />
</span></div>

<div><span id="spry_email">
<input name="email" type="text" id="email" value="email" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></div>

<div><span id="spry_phone">
<input name="phone" type="text" id="phone" value="phone" />
</span></div>

<div><span id="spry_enquiry">
<textarea name="enquiry" id="enquiry" cols="35" rows="6">enquiry</textarea>
<span class="textareaRequiredMsg">A value is required.</span></span></div>

<div>
<input name="submit" type="submit" value="submit" id="index-form-submit" />
</div>

</fieldset>
</form>

*** PHP Process Script ***
<?php

$name=$_POST['name'];
$company=$_POST['company'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$enquiry=$_POST['enquiry'];

$toaddress = 'email@email.com.au';

$subject = 'General Enquiry';

$mailcontent = "Name: ".$name."\n\n"
."Company: ".$company."\n\n"
."Email: ".$email."\n\n"
."Phone: ".$phone."\n\n"
."Enquiry: \n\n".$enquiry;

$fromaddress = "From: $email";

mail($toaddress, $subject, $mailcontent, $fromaddress);

?>

Open in new window

0
Comment
Question by:JiveMedia
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34108959
Hi JiveMedia,

I'd need to see the whole of the HTML (especially the javascript) to tell you but I am assuming something is not set right with the Spry Validation and thus the form submits.

0
 

Author Comment

by:JiveMedia
ID: 34109006
Hi jason1178,

Please see the attached.
I have removed client references and a few other bits of non essential information.

Thanks
enquiry-process.php
index.php
SpryValidationTextarea.css
SpryValidationTextField.js
SpryValidationTextField.css
SpryValidationTextarea.js
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 total points
ID: 34109069
Well, my initial idea was wrong.  Your Spry is fine.

>> Even with the Spry Validation, i keep getting blank emails sent through from the form to my email.

Because the form is processed on a separate page, robots can follow the form tag to that page and submit mail merely by accessing the page with a normal URL because you do nothing in enquiry-process.php to check to see if the form is submitted.

Try this:

<?php

if (isset($_POST['submit'])) {

$name=$_POST['name'];
$company=$_POST['company'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$enquiry=$_POST['enquiry'];

$toaddress = 'something@email.com.au';

$subject = 'General Enquiry';

$mailcontent = "Name: ".$name."\n\n"
."Company: ".$company."\n\n"
."Email: ".$email."\n\n"
."Phone: ".$phone."\n\n"
."Enquiry: \n\n".$enquiry;

$fromaddress = "From: $email";

mail($toaddress, $subject, $mailcontent, $fromaddress);

} else {

echo "Direct page access"

}

?>

and then test it by going to:

http://www.yourdomain.com/enquiry-process.php

You should see "Direct page access" but no mail sent.  Submitting the form should send mail.
0
 

Author Closing Comment

by:JiveMedia
ID: 34109141
Awesome, works great...thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question