Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-30-2008, 03:26 PM Help with headers...
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
I'm back again. Forgive my "noob" questions, but I'm having trouble with the email headers. Is there any way to have the "From" of an email replaced with the text of a form element? When the form submits without any $headers, I get an email from "myaccount(a)myserver.hostingcompany.com". When I add...
PHP Code:
$headers "From: $name_field"
...the email header is blank. When I use...
PHP Code:
$headers "From: 'name'"
...I get 'name'(a)myserver.hostingcompany.com. Is there any way to get the full text and just the text to appear? Here is the full code, if it helps.
PHP Code:
<?php
if(isset($_POST['submit'])) {

$to "fake@email";
$subject "Attendance Correction Form";
$headers "From: $name_field";
$forward 1;
$name_field $_POST['name'];
$department $_POST['department'];
$supervisor $_POST['supervisor'];
$date_correction $_POST['datecorrection'];
$time_in $_POST['timein'];
$lunch_out $_POST['lunchout'];
$lunch_in $_POST['lunchin'];
$time_out $_POST['timeout'];
 
$body "From: $name_field\n Department: $department\n Supervisor: $supervisor\n Date Needing Correction: $date_correction\n Time In: $time_in\n Lunch Out: $lunch_out\n Lunch In: $lunch_in\n Time Out: $time_out";
 
echo 
"Thank you. Your form has been submitted.";
mail($to$subject$body$headers);

} else {

echo 
"ERROR!";

}
?>
Thanks for the help!

Last edited by werm82; 09-30-2008 at 06:38 PM..
werm82 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-30-2008, 04:02 PM Re: Help with headers...
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
$name_field - check that you have defined this variable. Sound to me like your leaving it blank.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-30-2008, 05:03 PM Re: Help with headers...
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
I thought I did, around line 8ish...
PHP Code:
$name_field $_POST['name']; 
werm82 is offline
Reply With Quote
View Public Profile
 
Old 09-30-2008, 05:27 PM Re: Help with headers...
DigitaLink's Avatar
Average Talker

Posts: 16
Name: Chris
Trades: 0
It's a logic problem.
Quote:
$to = "you@yourhost.com";
$subject = "Attendance Correction Form";
$headers = "From: $name_field";
$forward = 1;
$name_field = $_POST['name'];
$department = $_POST['department'];
You've simply assigned $headers to contain the value of $name_field BEFORE you defined what $name_field actually contains. If you define $headers AFTER you assign $name_field = $_POST['name'], you'll be good to go.

Last edited by DigitaLink; 09-30-2008 at 07:50 PM.. Reason: Email removal from code requested by werm82
DigitaLink is offline
Reply With Quote
View Public Profile
 
Old 09-30-2008, 06:36 PM Re: Help with headers...
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Awesome! Worked like a charm. Now just one last question on the subject, and I'll hang it up. I get the name field to post, but it comes in as "Fake Name@NONE" in Outlook and "Fake@yahoo" in Yahoo Mail, etc. Anyway it can look like this?

werm82 is offline
Reply With Quote
View Public Profile
 
Old 09-30-2008, 06:56 PM Re: Help with headers...
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
make it
PHP Code:
<?php
if(isset($_POST['submit'])) {

$to "fake@email";
$name_field $_POST['name'];
$subject "Attendance Correction Form";
$headers 'From: '."$name_field <noreply@example.com>"."\r\n";
$forward 1;
$department $_POST['department'];
$supervisor $_POST['supervisor'];
$date_correction $_POST['datecorrection'];
$time_in $_POST['timein'];
$lunch_out $_POST['lunchout'];
$lunch_in $_POST['lunchin'];
$time_out $_POST['timeout'];
 
$body "From: $name_field\n Department: $department\n Supervisor: $supervisor\n Date Needing Correction: $date_correction\n Time In: $time_in\n Lunch Out: $lunch_out\n Lunch In: $lunch_in\n Time Out: $time_out";
 
echo 
"Thank you. Your form has been submitted.";
mail($to$subject$body$headers);

} else {

echo 
"ERROR!";

}
?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-30-2008, 08:30 PM Re: Help with headers...
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Thanks everyone for you help!
werm82 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with headers...
 

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25143 seconds with 12 queries