Solved

Blank emails from PHP Spry Form

Posted on 2010-11-10
4
510 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Awesome, works great...thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now