Solved

Blank emails from PHP Spry Form

Posted on 2010-11-10
4
513 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

809 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