Jump to content

[SOLVED] Change "From:" portion of Email


csramin

Recommended Posts

*Disclaimer: I don't know much (almost nothing) about PHP. Please use small words ;).

 

I created a Simple Feedback (mail) form in PHP, by following instructions in a book. It's pretty standard: User fills out form on website. Information gets send to mailbox.

 

It works almost perfectly. The only thing I need to do is get the "From:" portion of the email to change to the users email address. Right now any email that comes from a form on the site has "mysite"@box143.bluehost.com as the sender. Its kind of like a default box or something.

 

Anyway, Is there a standard command (i.e. $to = "", $subject = "") that I can use to change this like I did with the "Subject:"?

 

<?

$msg .= "PERSONAL INFO\n";
$msg .= "Name:                    $_POST[name] \n";
$msg .= "Company:               $_POST[company] \n";
$msg .= "Phone:                   $_POST[phone] \n";
$msg .= "Email:                     $_POST[email] \n\n";

$msg .= "City:                      $_POST[city] \n";
$msg .= "State:                    $_POST[state] \n";
$msg .= "Zip Code:                $_POST[zip] \n";
$msg .= "Country:                 $_POST[country] \n\n";

$msg .= "MESSAGE:                $_POST[message] \n\n";


$to = "[email protected]";
$subject = "Contact";

mail($to, $subject, $msg, $mailheaders);
?>

 

PLEASE HELP!

Link to comment
https://forums.phpfreaks.com/topic/50570-solved-change-from-portion-of-email/
Share on other sites

Here you go.  You never set a value for the variable "$mailheaders".  You can use this 4th parameter to specify from, CC and BCC.  Also if you are sending HTML (so NON plain text e-mails) from the script you can use this header variable to specify another "to" address...

 

$mailheaders = 'From: Your Website <[email protected]>' . "\r\n";
$mailheaders .= 'Cc: [email protected]' . "\r\n";
$mailheaders .= 'Bcc: [email protected]' . "\r\n";

That worked very nicely. It changed the "From:" portion of the email, but there's still a problem

What I need to change it to is the senders email.

 

$mailheaders = 'From: $_POST[email] <[email protected]>' . "\r\n";
$mailheaders .= 'Cc: [email protected]' . "\r\n";
$mailheaders .= 'Bcc: [email protected]' . "\r\n";

 

I totally made that code up and no it didn't work and you probably know why and are either shaking your head or laughing. That's okay.  My logic obviously isn't very PHP savvy. I think you get what I'm trying to do though. How do I get this to work?

 

PS I can get the "Reply-To:" to work. Thats not the issue.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.