Jump to content

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 = "info@mysite.com";
$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 <csramin@csramin.com>' . "\r\n";
$mailheaders .= 'Cc: address2@csramin.com' . "\r\n";
$mailheaders .= 'Bcc: another-address-here@csramin.com' . "\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] <contact@csramin.com>' . "\r\n";
$mailheaders .= 'Cc: address2@csramin.com' . "\r\n";
$mailheaders .= 'Bcc: another-address-here@csramin.com' . "\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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.