Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   php action script for forms (https://www.warriorforum.com/programming/826289-php-action-script-forms.html)

rhinocl 6th August 2013 01:42 PM

php action script for forms
 
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";
}
?>


webn 6th August 2013 04:46 PM

Re: php action script for forms
 
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.

egyptik 7th August 2013 04:15 AM

Re: php action script for forms
 
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.

rhinocl 7th August 2013 11:44 AM

Re: php action script for forms
 
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.

nmcc 9th August 2013 10:09 AM

Re: php action script for forms
 
The line:
$header="from: ".$_POST['name'] ."<".$_POST['mail_from'].">";

should be:
$header="from: ".$_POST['name'] ."<".$_POST['customer_mail'].">";

otfromtot 13th August 2013 12:32 PM

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

WMSTR 13th August 2013 02:37 PM

Re: php action script for forms
 
Are you sure mail(); function is turned on your server?

Some companys close this function.

I think you've to use smtp.


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