Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help Forums Windows Startup Programs Database Virus, Spyware, and Malware Removal Guides Computer Tutorials Uninstall Database File Database Computer Glossary Computer Resources
 

Welcome Guest ( Log In | Click here to Register a free account now! )



Register a free account to unlock additional features at BleepingComputer.com
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.
Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

 
Reply to this topicStart new topic
> PHP scripting Problems!, Linking conacts page submit botton to my email!
cap2587
post Jun 11 2009, 06:21 PM
Post #1


Forum Regular
***

Group: Members
Posts: 182
Joined: 19-September 08
Member No.: 239,884



I am trying to write the PHP scripting page on my website to link the submit botton on my contacts page with my email. I am following a Video on Youtube by Tutvid http://www.youtube.com/watch?v=rdsz9Ie6h7I

It is sending the email to my email, but doesn't have the email address of who sent it and just has email, phone, comments section, but no writing in the columns. Does anyone know what I might be doing wrong or offer a different tutorial or program to perform this task. Thanks.
Go to the top of the page
 
+Quote Post
KamakaZ
post Jun 11 2009, 08:45 PM
Post #2


Senior Member
****

Group: HJT Sophomore Classmen
Posts: 434
Joined: 26-August 08
From: Victoria
Member No.: 233,642



Have a read through this topic (both pages), i think you are trying to do a similar thing.


--------------------
If I am helping you and don't reply in 24 hours please send me a PM

Currently in training...

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.
Go to the top of the page
 
+Quote Post
cap2587
post Jun 14 2009, 10:28 AM
Post #3


Forum Regular
***

Group: Members
Posts: 182
Joined: 19-September 08
Member No.: 239,884



I read through this post, but I am still lost. Can someone take a look at my code and figure out what my problem is. The email is sent when the submit botton is pressed, but there is no email address from the sender and nothing written in the name, phone, email sections. Let me know if there is anything else you need. I used Tutvid's code for HTMLforPHP Form he had in his video where he said to put it. I made my own contacts page, didn't use his template. Could that be causing a problem. When someone presses submit it is suppose to say "Thank you for your interest! Your email will be answered very soon". it doesn't say that and just makes the contact page blank. Hoping I haven't confused you guys: I am very frustrated and would love to figure this out. Thanks

<?php


/* Subject and email variables */

$emailSubject = 'Crazy PHP Scripting!';
$webMaster = 'fixthatglitch@hotmail.com';

/*gathering Data Variables*/

$emailField = $_POST['Email'];
$nameField = $_POST['Name'];
$phoneField = $_POST['Phone'];
$commentsField = $_POST['Comments'];

$Body = <<<EOD
<br><hr><br>
Email: $Email <br>
Name: $Name <br>
Phone: $Phone <br>
Comments: $Comments <br>
EOD:

$headers = "From: $Email\r\n";
$headers .= "Content type : text/html\r\n";
$success = mail($webMaster, $emailSubject, $Body, $headers);

/* Results rendered as HTML/*


$theResults = <<<EOD
<html>
<head>
<title>JakesWorks - travel made easy-Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>

<div>
<div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";


?>

Go to the top of the page
 
+Quote Post
JJ2K
post Jun 15 2009, 06:26 PM
Post #4


Member
**

Group: Members
Posts: 134
Joined: 23-January 09
Member No.: 286,225



Is that the full code? Because obviously from what I remember you can't just put random HTML into PHP you have to close your PHP code block first if you want to use HTML unless you're using an echo or print statement (I think).

I haven't tried this in a while so thought i'd have a go at it, i'll show you step by step:

1. OK let's tackle your first problem: When someone presses submit it is suppose to say "Thank you for your interest! Your email will be answered very soon".


OK let's take a simple document and another PHP document to handle the form:
Here is the simple form, save it as form.php:

E-mail Form: (form.php):
QUOTE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="email" action="handleMail.php" method="post">
Name:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="name" size="20" /><br /><br />
Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="sender" width="20" /><br /><br />
Phone:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="phone" width="20" /><br /><br />
Subject:&nbsp;&nbsp; <input type="text" name="subject" size="75" /><br /><br />
Comments:&nbsp; <textarea name="comments" cols="75" rows="5">
Comments
</textarea><br /><br />
<input type="submit" value="Send E-Mail" />
</form>
</body>
</html>


OK now here is the PHP to handle the form save this as handleMail.php:

QUOTE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>Thank you for your interest! Your email will be answered very soon!</p>
</body>
</html>



OK so hopefully now you've saved form.php and handleForm.php. Now open form.php and basically enter nothing in the form and press submit. Thank you for your interest! Your email will be answered very soon! will be displayed.

How: Because in our form, we say: action="handleMail.php" which tells it what document to look for to handle the form when the submit button is pressed.



2. OK now i'm going to change handleMail.php to pass on the variables that will be sent by the form. Then i'll display the variables just to show that they have been passed.

Here's the new handleForm.php, so save it over the last one:

QUOTE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

//Default
$Webmaster = 'fixthatglitch@hotmail.com';

//assign from form to variables
$name = $_POST['name'];
$sender = $_POST['sender'];
$subject = $_POST['subject'];
$phone = $_POST['phone'];
$body = $_POST['comments'];


//Now let's test they have been passed and show them
echo ("Thanks $name for your response, as outlined below<br /><br />");
echo ("<b>$subject</b><br />");
echo ("\"<i>$body</i>\"<br /><br />");
echo ("We will either contact you via e-mail at: <b>$sender</b> or via phone on <b>$phone</b> within the next 24 hours.<br />");


?>


</body>


</html>


OK now again open form.php, this time enter some dummy data in each of the boxes and press send e-mail. As you can see the variables are passed, and your data should be displayed. If this works correctly move onto the final step

3. Now we know all the data is passing successfully we can now easily send the mail, this is the final handleMail.php:


QUOTE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

//Default
$Webmaster = 'fixthatglitch@hotmail.com';

//assign from form to variables
$name = $_POST['name'];
$sender = $_POST['sender'];
$subject = $_POST['subject'];
$phone = $_POST['phone'];
$body = $_POST['comments'];


//Now let's test they have been passed and show them
echo ("Thanks $name for your response, as outlined below<br /><br />");
echo ("<b>$subject</b><br />");
echo ("\"<i>$body</i>\"<br /><br />");
echo ("We will either contact you via e-mail at: <b>$sender</b> or via phone on <b>$phone</b> within the next 24 hours.<br />");

//Join sender e-mail and phone number to create a single header
$headers = "From: ".$sender.", Phone: ".$phone;
//Now send mail
mail ($webmaster, $subject, $body, $headers);
?>


</body>


</html>


As you can see only the 2 lines were added, the first was to create a $headers variable, and the second sends the e-mail. You will need to modify this probably to connect to your e-mail or whatever.

I'd be greatful for any feedback if i've done anything wrong but just trying to learn myself!

This post has been edited by JJ2K: Jun 15 2009, 06:35 PM
Go to the top of the page
 
+Quote Post
groovicus
post Jun 15 2009, 07:58 PM
Post #5


Hail Groovicus!
******

Group: Site Admin
Posts: 7,900
Joined: 5-June 04
From: Centerville, SD
Member No.: 689



I guess my big question is why you would be surrounding a variable in quotes??
echo "$theResults";

You may also want to do a little more searching. The code you used has a bunch of other problems that have been discussed on a bunch of other forums.


--------------------
Never Argue With Stupid People



Microsoft Senior Student Partner
Go to the top of the page
 
+Quote Post
KamakaZ
post Jun 15 2009, 10:18 PM
Post #6


Senior Member
****

Group: HJT Sophomore Classmen
Posts: 434
Joined: 26-August 08
From: Victoria
Member No.: 233,642



First of all, how much do you know about php?

I'd try having a read through this.

It should help you understand what's going on with your form.


--------------------
If I am helping you and don't reply in 24 hours please send me a PM

Currently in training...

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.
Go to the top of the page
 
+Quote Post
cap2587
post Jun 17 2009, 08:32 PM
Post #7


Forum Regular
***

Group: Members
Posts: 182
Joined: 19-September 08
Member No.: 239,884



Thanks for all your help on my PHP issue. I have never done PHP scripting before this and have been frustrated by my failure to do this. However, I persevered and finally figure it out. Appreciate the help.
Go to the top of the page
 
+Quote Post
groovicus
post Jun 17 2009, 09:12 PM
Post #8


Hail Groovicus!
******

Group: Site Admin
Posts: 7,900
Joined: 5-June 04
From: Centerville, SD
Member No.: 689



QUOTE
I have never done PHP scripting before this and have been frustrated by my failure to do this. However, I persevered and finally figure it out.


That's great, but I bet a bunch of your frustration came from worthless links that went nowhere. Do you mind sharing what you did so that this just doesn't become another wasted thread? smile.gif


--------------------
Never Argue With Stupid People



Microsoft Senior Student Partner
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 8th November 2009 - 02:39 AM


Advertise   |   About Us   |   Terms of Use   |   Privacy Policy   |   Contact Us   |   Site Map   |   Chat   |   Tutorials   |   Uninstall List
Discussion Forums   |   The Computer Glossary   |   Resources   |   RSS Feeds   |   Startups   |   The File Database   |   Virus Removal Guides

© 2003-2009 All Rights Reserved Bleeping Computer LLC.