Copy link to clipboard
Copied
I am having a problem with writing some PHP script in an attempt to draw info, entered by users, on a form on my site and email it to myself. The form is on the website page www.highwaytoheavenchurch.com/prayerRequest.php
In lesson 13 of the textbook "Classroom in a Book for Adobe Dreamweaver CS5" it takes you through the PHP script for emailing forms and gives a great example to follow. I adapted this example to fit my needs. Here is the script I have written;
<?php
$to = "edjax1952@yahoo.com";
$subject = "Website Prayer Request";
$message =
"Name: ". $_POST['name'] . "\r\n" .
"Email: " . $_POST['email']. "\r\n" . "\r\n" .
"Prayer Request:" . $_POST['prayerRequest'];
$from = $_POST['email'];
$headers = "From: $from" . "\r\n";
mail($to,$subject,$message,$headers);
?>
The html for the form is:
<form action="email_form.php" method="post" enctype="multipart/form-data" name="websitePrayerRequest" id="websitePrayerRequest">
<p>
</p>
<fieldset>
<legend>Name and Email</legend><p>
<label id="name">Name (not required)
<input name="name" type="text" id="name" size="30" maxlength="30">
</label>
</p>
<p><span id="email">
<label for="email">Email</label>
<input type="text" name="email" id="email">
<span class="textfieldRequiredMsg">An email address is required.</span><span class="textfieldInvalidFormatMsg">Please enter a valid email address.</span></span></p></fieldset>
<p>
</p>
<p>Enter your prayer request here:</p>
<p>
<textarea name="prayerRequest" cols="75" rows="8" id="prayerRequest"></textarea>
</p>
<p>
<label>
<input type="submit" name="Submit" id="submit" value="Submit">
Submit Your Request</label>
</p>
</form>
The result is that the form will email me with the sender being the name of my FTP account of my hosting provider (this is acceptable), and the following info in the body of the email:
Name:
Email:
Prayer Request:
Obviously, it does not draw the information typed into the form text boxes by the user.
Do you have any suggestions for me?
Copy link to clipboard
Copied
Unless you are doing a file upload, you should not use the enctype="multipart/form-data". I'm not sure if that's causing the problem, but try removing that tag. Also, I don't code in PHP, but that script sure doesn't look secure to me. You're not doing any data validation. Check with someone that knows PHP to be sure.
Copy link to clipboard
Copied
The form is being transmitted from a secure site. The data in the email is not stored on the site. It is transmitted in the email to me and then stored in my personal inbox.
I have deleted the scriptyou suggested and still get the same reasults. The form HTML now reads:
<form action="email_form.php" method="post" name="websitePrayerRequest" id="websitePrayerRequest">
<p>
</p>
<fieldset>
<legend>Name and Email</legend><p>
<label id="name">Name (not required)
<input name="name" type="text" id="name" size="30" maxlength="30">
</label>
</p>
<p><span id="email">
<label for="email">Email</label>
<input type="text" name="email" id="email">
<span class="textfieldRequiredMsg">An email address is required.</span><span class="textfieldInvalidFormatMsg">Please enter a valid email address.</span></span></p></fieldset>
<p>
</p>
<p>Enter your prayer request here:</p>
<p>
<textarea name="prayerRequest" cols="75" rows="8" id="prayerRequest"></textarea>
</p>
<p>
<label>
<input type="submit" name="Submit" id="submit" value="Submit">
Submit Your Request</label>
</p>
</form>
Copy link to clipboard
Copied
The reason the form is empty is because there is improper use of the ID tag on your page. The purpose behind an ID is to uniquely identify a SINGLE element on the page. Thus in your case the Label "name" and the Span "email" are being recorded because they appear first in the context of the page.
The top part for the "name" field. The label HTML should be:
<label for="name">
And for the email the span you can just delete the " id="email" " part.
Also as I dig further, you are hosting with Godaddy and if this post is true ( http://support.godaddy.com/groups/web-hosting/forum/topic/problem-with-sending-email-using-php-mail-... ) Godaddy will block any email sent to a Yahoo or other email address not hosted with them.
Copy link to clipboard
Copied
I agree with bregent, the multipart is not needed. Regardless of security at this point, is the email being sent with blank data or is the email not sent at all? Where does the problem start?
Copy link to clipboard
Copied
The email is being sent to me with the sender being the name of my FTP account of my hosting provider (this is acceptable), and the following info in the body of the email:
Name:
Email:
Prayer Request:
Since I am receiving an email, I conclude that the script has instruction to send the variables I have included in the script but no instructions to transmit the user input (in the text boxes).
The Dreamweaver software detects syntax errors. There are none. Possibly, there needs to be instructions for gathering and transmitting the user input.