BleepingComputer.com: PHP scripting Problems!

Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, 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.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP scripting Problems! Linking conacts page submit botton to my email!

#1 User is offline   cap2587 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 428
  • Joined: 19-September 08

Posted 11 June 2009 - 06:21 PM

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.

#2 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 11 June 2009 - 08:45 PM

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

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.

#3 User is offline   cap2587 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 428
  • Joined: 19-September 08

Posted 14 June 2009 - 10:28 AM

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";


?>

#4 User is offline   JJ2K 

  • Forum Regular
  • PipPipPip
  • Find Topics
  • Group: Members
  • Posts: 162
  • Joined: 23-January 09

Posted 15 June 2009 - 06:26 PM

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: 15 June 2009 - 06:35 PM


#5 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 15 June 2009 - 07:58 PM

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#6 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

Posted 15 June 2009 - 10:18 PM

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

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.

#7 User is offline   cap2587 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 428
  • Joined: 19-September 08

Posted 17 June 2009 - 08:32 PM

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.

#8 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 17 June 2009 - 09:12 PM

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? :thumbsup:
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users