Closed Thread
Thread Tools Search this Thread
Unread 6th Aug 2013, 01:42 PM   #1
Senior Warrior Member
War Room Member
 
Join Date: 2009
Posts: 1,057
Thanks: 124
Thanked 198 Times in 147 Posts
Default
php action script for forms
Share on: 
fb share twitter share gplus share more share

I found this simple script on the web and started to play with it. For some reason it sends me emails but I dont get any of the fields returned. I get the message that "We've recived your information" and I get an email but they are always empty. The names and Ids of the fields in the form are:
subject,detail,customer_mail,name

Code:
<?php

// Contact subject
$subject ="$subject";

// Details
$message="$detail";


// Mail of sender
$mail_from="$customer_mail";

// From
$header="from: $name <$mail_from>";


// Enter your email address
$to ='myemailaddress.info';

$send_contact=mail($to,$subject,$message,$header);


// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>

rhinocl is offline  
Unread 6th Aug 2013, 04:46 PM   #2
HyperActive Warrior
 
Join Date: 2010
Posts: 160
Thanks: 26
Thanked 14 Times in 10 Posts
Default
Re: php action script for forms
Share on: 
fb share twitter share gplus share more share

If you just upload this script, you can't see any Subject/Detail or anything. Because, the subject/details are generated dynamically from the form page that is missed here.

If you don't understand what I mean then, read any php book (form chapter) or use this tutorial "PHP Forms"

Hope it helps.
webn is offline  
Unread 7th Aug 2013, 04:15 AM   #3
Web Developer
War Room Member
 
egyptik's Avatar
 
Join Date: 2013
Location: The Netherlands
Posts: 115
Thanks: 9
Thanked 71 Times in 18 Posts
Default
Re: php action script for forms
Share on: 
fb share twitter share gplus share more share

OK, I assume this is how you have your script set up:

You have a form page (not displayed in your post), which upon form submission posts it to your action script above. I also assume the PHP script posted above is the full action script, without you having left any code out.

Here is your problem: you assign variables to other variables, which are empty. That's why you recieve empty emails. In fact, the only var you did correctly assign, is the 'to' email adress.

Example: $subject = "$subject";
You are assigning an empty var to itself, this equals: $subject = "";

I assume you are confusing this with the form field names. If that is the case, this code should work for you:

Code:
<?php

// Contact subject
$subject = $_POST['subject'];

// Details
$message= $_POST['detail'];


// Mail of sender
$mail_from= $_POST['customer_mail'];

// From
$header="from: ".$_POST['name'] ."<".$_POST['mail_from'].">";


// Enter your email address
$to ='myemailaddress.info';

$send_contact=mail($to,$subject,$message,$header);


// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
Or if you used the GET method, replace all $_POST vars with $_GET.
egyptik is offline  
The Following User Says Thank You to egyptik For This Useful Post:
Unread 7th Aug 2013, 11:44 AM   #4
Senior Warrior Member
War Room Member
 
Join Date: 2009
Posts: 1,057
Thanks: 124
Thanked 198 Times in 147 Posts
Default
Re: php action script for forms
Share on: 
fb share twitter share gplus share more share

Thanks good to know it was the page I copied not me.
That gives me the info from the input fields in the body but I get this in the from field:

Code:
jimmyg@, UNEXPECTED_DATA_AFTER_ADDRESS@.SYNTAX-ERROR.

rhinocl is offline  
Unread 9th Aug 2013, 10:09 AM   #5
CyberGeek
War Room Member
 
nmcc's Avatar
 
Join Date: 2012
Posts: 51
Thanks: 6
Thanked 17 Times in 15 Posts
Default
Re: php action script for forms
Share on: 
fb share twitter share gplus share more share

The line:
$header="from: ".$_POST['name'] ."<".$_POST['mail_from'].">";

should be:
$header="from: ".$_POST['name'] ."<".$_POST['customer_mail'].">";
nmcc is offline  
The Following User Says Thank You to nmcc For This Useful Post:
Unread 13th Aug 2013, 12:32 PM   #6
TNT
 
otfromtot's Avatar
 
Join Date: 2012
Location: florida
Posts: 65
Thanks: 19
Thanked 5 Times in 5 Posts
Default
Re: php action script for forms
Share on: 
fb share twitter share gplus share more share

I just use this. I've actually used it for almost ten years I think
Matt's Script Archive: FormMail

If everyone knew everything the world sure would be irritating
otfromtot is offline  
Unread 13th Aug 2013, 02:37 PM   #7
echo 'Hello World!';
 
Join Date: 2013
Location: Istanbul
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: php action script for forms
Share on: 
fb share twitter share gplus share more share

Are you sure mail(); function is turned on your server?

Some companys close this function.

I think you've to use smtp.
WMSTR is offline  
Closed Thread


Bookmarks

Tags
action, forms, php, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 06:30 AM.