| | #1 |
| Senior Warrior Member War Room Member Join Date: 2009
Posts: 1,057
Thanks: 124
Thanked 198 Times in 147 Posts
|
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";
}
?> |
| | |
| |
| | #2 |
| HyperActive Warrior Join Date: 2010
Posts: 160
Thanks: 26
Thanked 14 Times in 10 Posts
|
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. |
| |
| | #3 |
| Web Developer War Room Member Join Date: 2013 Location: The Netherlands
Posts: 115
Thanks: 9
Thanked 71 Times in 18 Posts
|
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";
}
?> |
| |
| The Following User Says Thank You to egyptik For This Useful Post: |
| | #4 |
| Senior Warrior Member War Room Member Join Date: 2009
Posts: 1,057
Thanks: 124
Thanked 198 Times in 147 Posts
|
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. |
| | |
| |
| | #5 |
| CyberGeek War Room Member Join Date: 2012
Posts: 51
Thanks: 6
Thanked 17 Times in 15 Posts
|
The line: $header="from: ".$_POST['name'] ."<".$_POST['mail_from'].">"; should be: $header="from: ".$_POST['name'] ."<".$_POST['customer_mail'].">"; |
| |
| The Following User Says Thank You to nmcc For This Useful Post: |
| | #6 |
| TNT Join Date: 2012 Location: florida
Posts: 65
Thanks: 19
Thanked 5 Times in 5 Posts
|
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
| |
| |
| | #7 |
| echo 'Hello World!'; Join Date: 2013 Location: Istanbul
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
Are you sure mail(); function is turned on your server? Some companys close this function. I think you've to use smtp. |
| |
|
| Bookmarks |
| Tags |
| action, forms, php, script |
| |