mail script

This is a discussion on "mail script" within the PHP Forum section. This forum, and the thread "mail script are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 3rd, 2006, 22:56
Junior Member
Join Date: Jun 2006
Location: Ireland
Age: 18
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
mail script

Ive set up this mail script and im having trouble actually recieving the form are thier any glaring mistakes in it?

<?php
if ($_POST) {
if (GET_MAGIC_QUOTES_GPC()) {
foreach ($_POST as $key => $value) {
$temp = stripslashes($value);
$_POST[$key] = $temp;
}
}
$to = 'forzaparma1@gmail.com';
$subject = 'Link Exchange';
$message = "From:".$_POST['name']."\n";
$message .= "Email:".$_POST['email']."\n";
$message .= "Website:".$_POST['site'];
$headers = "Reply-To:".$_POST['email'];
$sent = mail($to, $subject, $message, $headers);
}
?>
Reply With Quote

  #2 (permalink)  
Old Jul 4th, 2006, 16:40
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: mail script

It's only an assumption on my part as I've never seen it explicitely stated but I always assumed that, as far as the script was concerned, the globals like $_POST were read only. You are trying to write to it.

I think you should rethink how you pick up your incoming variable values and clean them.
Reply With Quote
  #3 (permalink)  
Old Jul 4th, 2006, 18:12
Junior Member
Join Date: Jun 2006
Location: Ireland
Age: 18
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Re: mail script

I'm not exactly sure what you mean but this is the rest of the script

<?php if (isset($sent)) { echo '<p>Thank you, your details have been sent.</p>'; } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
Reply With Quote
  #4 (permalink)  
Old Jul 5th, 2006, 09:10
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: mail script

I'm thinking something like:

Code: Select all
if (...){
   $messsage = "From: ".stripslashes($_POST['name']);
   ...
}
Reply With Quote
  #5 (permalink)  
Old Jul 5th, 2006, 12:36
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: mail script

Does the message send and not get received, or not get sent? You might check your mail settings in php.ini to make sure your server doesn't have rules you are breaking and isn't routing it through a server that won't process it without something you are lacking, like SMTP authentication.

The code itself is not something I can read well enough to give you a definitive answer, especially the "to" injection. The first thing I would do is echo the message to myself, to see the output. If it looked good, I would replace the TO header with my email address and see if it goes through. If not, you'll have to do a bit of code to give you a boolean response if the message is sent.

I wouldn't use << if($_POST) >>, mostly because I'm not familiar with it, and actually wouldn't use << if(!empty($_POST)) >> which is the syntax I learned. I'd do a different IF clause for each variable and put any error message into an errors array, inside the IF $sent clause, like
Code: Select all
$errors=array; if (empty($_POST['name'])) {$errors[] = 'You didn't fill in the "from" line.';}
Then all you have to do is << if(empty($errors)) >> That way you won't trigger $sent with missing fields and won't stop the script on each mistake.

There are a couple of sophisticated touches in your code. (Where'd you come up with << $_POST[$key] = $temp; >>? That's pretty ingenious if it works.) If this comes from Dreamweaver, it might be adding a space before the globals. I don't use it, but I've heard of this. My guess is you would need some sort of substring code to take it out, it would certainly mess you up.

One other thought if you suspect the problem is with a server, is to use PEAR.
Reply With Quote
  #6 (permalink)  
Old Jul 5th, 2006, 12:39
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: mail script

Sorry, that would be << $errors = array(); >>
Reply With Quote
  #7 (permalink)  
Old Jul 5th, 2006, 12:48
Junior Member
Join Date: Jun 2006
Location: Ireland
Age: 18
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Re: mail script

The form is sent I know this because the code
<?php if (isset($sent)) { echo '<p>Thank you, your details have been sent.</p>'; } ?> is displayed it just isnt getting recieved to my email.....I don't know where I came up with the code exactly I just read a few tutorials and pieced together what I knew....it isnt very sophisticated as to have code that stops spammers and such.....I should put in error mesages which I will do by making all fields required once I get the script to recieve...I've checked with my host the script is in compliance with all the rules set and such at least thats what tech support said....Ill read up some more and use a proven code before I try put together my own!
Reply With Quote
Reply

Tags
mail, script

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] parse error, unexpected T_EXIT in php mail script Posie PHP Forum 8 Dec 13th, 2007 14:21
Can someone help me with this e-mail form??? johnson8707 PHP Forum 4 Jul 4th, 2006 17:51
e-mail lookup pengyou PHP Forum 4 Feb 16th, 2006 13:01
visitors name not displayed in mail after filling in mail form made on earth PHP Forum 7 Nov 16th, 2005 22:43
PHP form mail script required... JohneeMac PHP Forum 7 Sep 27th, 2004 18:54


All times are GMT. The time now is 22:15.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43