Solved

Blank emails from PHP Spry Form

Posted on 2010-11-10
4
518 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 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