dlcmpls Posted December 18, 2007 Share Posted December 18, 2007 Hello all. I have no hair left! I'm working with a very simple email script, but I'm having trouble getting the script to work with a "from" email address supplied via a form (or even hard coded). Here's the code that I know works (with no references to the external form) <? $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: $from"; mail($to,$subject,$message,$headers); ?> Works a-ok. But, now I want the "From" email address to be the email supplied by the user of the form. So I have an input field called "Email" in my form. If I try to modify the above code like so: <? $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: ($_POST)"; mail($to,$subject,$message,$headers); ?> No email gets sent. In fact, I can't even set a hard code my own variable in the above code like so: <?php $myemail="[email protected]"; $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: $myemail"; mail($to,$subject,$message,$headers); ?> That doesn't work. No email gets sent which confuses me because I'm simply replacing one variable ($from) with another ($myemail) in the $headers line. What am I missing? Any help would be greatly appreciated. dlc Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 18, 2007 Share Posted December 18, 2007 <?php $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: " . $_POST['Email']; mail($to,$subject,$message,$headers); ?> PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417424 Share on other sites More sharing options...
dlcmpls Posted December 18, 2007 Author Share Posted December 18, 2007 Thanks phreeek. but that didn't work. I tried this code: <?php $myemail="[email protected]"; $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: " . "$myemail"; mail($to,$subject,$message,$headers); ?> And no luck. One thing I don't understand at all...why would replacing one variable ($from) with another ($myemail) cause a problem to begin with? Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417428 Share on other sites More sharing options...
Northern Flame Posted December 18, 2007 Share Posted December 18, 2007 <?php $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = $_POST['email']; $headers = "From: $from"; mail($to,$subject,$message,$headers); ?> what is the name of the input field for the email? if it is not email, then replace $_POST['email'] with $_POST['NameHere'] obviously putting the name of the input field where it says NameHere Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417431 Share on other sites More sharing options...
dlcmpls Posted December 18, 2007 Author Share Posted December 18, 2007 Yep, I understand that Flame. Let's drop the idea of a form for now. Why doesn't this script work: <?php $myemail="[email protected]"; $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: " . "$myemail"; mail($to,$subject,$message,$headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417434 Share on other sites More sharing options...
Northern Flame Posted December 18, 2007 Share Posted December 18, 2007 what web host are you with? Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417437 Share on other sites More sharing options...
dlcmpls Posted December 18, 2007 Author Share Posted December 18, 2007 i use a webhost in minneapolis, visi.com. The files are on a Windows server. Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417439 Share on other sites More sharing options...
Northern Flame Posted December 18, 2007 Share Posted December 18, 2007 is php enabled in your server? I dont think comes installed in windows servers.... Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417441 Share on other sites More sharing options...
dlcmpls Posted December 18, 2007 Author Share Posted December 18, 2007 Yes, php is enabled. To recap, this code works fine: <?php $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: $from"; mail($to,$subject,$message,$headers); ?> and an email gets sent. But with this code, no email is sent: <?php $myemail="[email protected]"; $to = "[email protected]"; $subject = "Check it out!"; $message = "test message"; $from = "[email protected]"; $headers = "From: $myemail"; mail($to,$subject,$message,$headers); ?> I don't understand why simply changing the name of the variable in $headers line would disable the script. Quote Link to comment https://forums.phpfreaks.com/topic/82142-from-header-in-small-email-script/#findComment-417448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.