Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-22-2004, 07:22 PM   PM User | #1
chilipie
Senior Coder

 
chilipie's Avatar
 
Join Date: Jul 2004
Location: Shrewsbury, UK Age: 16
Posts: 1,117
Thanks: 0
Thanked 0 Times in 0 Posts
chilipie is an unknown quantity at this point
mail() Problem

Not working for some reason. It's probably some really stupid mistake - I'm pretty crap at PHP .
PHP Code:
<?php

if($submit) {

if (
$Name && $Email && $Subject && $Message) {

mail("ollie.craig@virgin.net""$Subject""$Message""From: $Name - $Email") or die("Sorry, there has been an error.");

header("refresh: 0; url=contactdone.php");

} else {

echo 
"You must fill in all of the fields.";

}

}

?>
Thanks,
Ol.

Last edited by chilipie; 11-22-2004 at 07:32 PM..
chilipie is offline   Reply With Quote
Old 11-22-2004, 08:07 PM   PM User | #2
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
When you say "not working", what do you mean exactly?

Is nothing happening? Are you getting a blank page?

Or does it print "You must fill in all of the fields.", or "Sorry, there has been an error."?

Aside from the email being sent, what else is supposed to happen? Maybe you should input some more debugging code (more echoes, etc..). Is something happening that isn't supposed to be happening?

Perhaps some of those variables you're testing for don't exist? IE. $Name should actually be $_GET['Name'] or $_POST['Name'] or something...

Regardless, your post was quite vague and it's hard to troubleshoot what the problem is as it could be anything. Please fill in some blanks and hopefully we can help you resolve this issue.

Good luck,
Sadiq.
sad69 is offline   Reply With Quote
Old 11-22-2004, 08:08 PM   PM User | #3
chilipie
Senior Coder

 
chilipie's Avatar
 
Join Date: Jul 2004
Location: Shrewsbury, UK Age: 16
Posts: 1,117
Thanks: 0
Thanked 0 Times in 0 Posts
chilipie is an unknown quantity at this point
Sorry, I should have been more specific.

Basically, when I try to submit the form (with or without data in the input fields) I just end up at a blank page. For in action: http://redblizzard.astahost.com/contact.php
chilipie is offline   Reply With Quote
Old 11-22-2004, 08:23 PM   PM User | #4
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
Yes, I think it's got to do with accessing your variables ($Name versus $_GET['Name']).

Try this code instead:
PHP Code:
<?php 

 
if(isset($_GET['submit'])) { 
  echo 
'Submit is set!<br/>';
  if (!empty(
$_GET['Name']) && !empty($_GET['Email']) && !empty($_GET['Subject']) && !empty($_GET['Message'])) {
   echo 
'Sending email!</br>'
   
mail("ollie.craig@virgin.net""$_GET['Subject']""$_GET['Message']""From: $_GET['Name'] - $_GET['Email']") or die("Sorry, there has been an error."); 

   
header("refresh: 0; url=contactdone.php"); 
  } 
  else { 
   echo 
"You must fill in all of the fields."
  } 
 } 
 else {
  echo 
'Submit not set...<br/>';
 }

?>
If that seems to work after your various testing you can remove the unnecessary echoes as you see fit.

Another area where you may or may not run into problems is in your php.ini file: you need to setup your SMTP server for the mail() function. If it's not set to a valid SMTP server, your mail() function won't send emails anywhere and may error out...

Edit:
You may or may not have noticed this (or known this), but I accessed your form elements through the $_GET array as the METHOD attribute of your form held GET as the value. Had it held POST, I would've used the $_POST array to access your form elements.


Hope that helps,
Sadiq.

Last edited by sad69; 11-22-2004 at 08:25 PM.. Reason: get/post edumacation..
sad69 is offline   Reply With Quote
Old 11-22-2004, 08:41 PM   PM User | #5
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,896
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
also (read Carl_McDades post in this forum) use location header not refresh...

header("location:contactdone.php");
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 11-22-2004, 08:47 PM   PM User | #6
chilipie
Senior Coder

 
chilipie's Avatar
 
Join Date: Jul 2004
Location: Shrewsbury, UK Age: 16
Posts: 1,117
Thanks: 0
Thanked 0 Times in 0 Posts
chilipie is an unknown quantity at this point
Quote:
Originally Posted by sad69
Another area where you may or may not run into problems is in your php.ini file: you need to setup your SMTP server for the mail() function. If it's not set to a valid SMTP server, your mail() function won't send emails anywhere and may error out...
I don't have access to the sever, so that might be a problem. However, I've used PHPFormGenerator, and the mail() function in the form worked then.

I got a parse error this time...
Quote:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/redblizz/public_html/contactprocess.php on line 7
I'll try with POST instead of GET, and see if that works.
chilipie is offline   Reply With Quote
Old 11-22-2004, 10:25 PM   PM User | #7
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
I'm not sure if this is the problem (I never keep variables inside of double-quotes, I usually close the string and concatenate...).

One of the following 2 line 7's might work:
PHP Code:
mail("ollie.craig@virgin.net""{$_GET['Subject']}""{$_GET['Message']}""From: {$_GET['Name']} - {$_GET['Email']}") or die("Sorry, there has been an error."); 
or:
PHP Code:
mail("ollie.craig@virgin.net"$_GET['Subject'], $_GET['Message'], "From: ".$_GET['Name']." - ".$_GET['Email']) or die("Sorry, there has been an error."); 
Let me know if that works.

Sadiq.
sad69 is offline   Reply With Quote
Old 11-23-2004, 07:31 AM   PM User | #8
chilipie
Senior Coder

 
chilipie's Avatar
 
Join Date: Jul 2004
Location: Shrewsbury, UK Age: 16
Posts: 1,117
Thanks: 0
Thanked 0 Times in 0 Posts
chilipie is an unknown quantity at this point
Nope :shakes head:
I've been looking at the documentation about the mail() function on PHP.net, but can't seem to find anything wrong...
chilipie is offline   Reply With Quote
Old 11-23-2004, 08:02 AM   PM User | #9
Nikita
New Coder

 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Nikita is an unknown quantity at this point
Here is my version of the code. It first checks to see if any of the variables you are sending are empty if not then it sends you the email. I have tested this script of mine and it works 100% without problems! I did notice that someone could easily flood you with emails by going to that url six or seven hundred times. I suggest you add a cookie that limits how many emails they could send per hour and maybe add some other protection.

Code:
<?php

error_reporting(0);

if(!empty($_GET['Name']) and !empty($_GET['Email']) and !empty($_GET['Subject']) and !empty($_GET['Message']))
{

mail("ollie.craig@virgin.net",$_GET['Subject'],$_GET['Message'],"From:<".$_GET['Name'].">".$_GET['Email']) or die("Mail() Failed.");

header("refresh: 0; url=contactdone.php");
}
else
{
die("You left a part of the form blank. Please hit your browsers back button and verify you have all parts of the form filled out.");
}

?>
__________________
Nikita
Контакт: Nikita.05@gmail.com
Nikita is offline   Reply With Quote
Old 11-23-2004, 03:27 PM   PM User | #10
chilipie
Senior Coder

 
chilipie's Avatar
 
Join Date: Jul 2004
Location: Shrewsbury, UK Age: 16
Posts: 1,117
Thanks: 0
Thanked 0 Times in 0 Posts
chilipie is an unknown quantity at this point
Thanks Nikita. Works fine .
chilipie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:16 PM.


Advertisement
Log in to turn off these ads.