Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Blank emails from PHP Spry Form

Posted on 2010-11-10
4
Medium Priority
?
521 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 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