PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
How do you display an email address or name as the sender when you process an HTML form using PHP. Here is my PHP code:
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
How the sender name is displayed will be determined by the server. IIS/Windows servers usually croak when trying to use the format ' "Sender Name" <sender@email.com> ' while *nix servers seem to be OK with it. IIS/Windows server seem to be ok with '<sender@email.com>' however, and *nix handle that well, so if you are going to use either format, I would shoose the latter.
But I would more strongly suggest using a package mailer like Swift.
You use the format: "Real Name" <email@address>
or Real Name <email@address> without the quotes.
mail() supports that for the $to field but seems to strip it down to just "<email@address>" for sending. You can add your own "To:" header in the additional headers for mail() but mail() isn't clever enough to know not to place it's own "To:" header their to prevent duplicates. I'm going through this headache at the moment to make a NativeMail connection for Swift. Urghh.
Thank you all for your input. I still haven't quite worked out the quirks but I'll get there hopefully. When the PHP code processes the HTML form and sends the email this is what shows:
It's the FROM section that I would like to change. I want it to say something like FROM: Site.
I would prefer to use Swift or some tool like Swift but at this point my PHP knowledge is still green so I am just trying to get the form working properly util I have more time to try and implement Swift.
i think thats changed in your php.ini file under sendmail_from...heres something that feyd sent me a while ago when i posted a similar question...i think this might help you out
edited
right before that line youll see a line that says "for win32 only"
after that youll see
sendmail_from= me@example.com <-change that to reflect what your wanting it to say
You can actually hardcode that into your code. Please note, this is purely for learning. There a lot of things to do with this if you want to actually use it in production.
You're welcome. Just make sure to not use the code I posted as is. It needs some security features in place (like injection preventing, XSS preventing and POST data validation). But I am glad you got your problem solved.
if (preg_match('/[^\x20-\x7E]/', $header_stuff))
{
//don't send as is
}
else
{
//Okie doke, just send
}
That's extremely basic and prevents extended UTF-8 characters from being sent too which is not good. Many email servers still do not support 8bit characters in the email (they can't process them for relaying). In that case you need to encode the headers to make them 7bit (base64, or quoted-printable). I'm not going to get into that area if you're new to it but any mailing library worth it's salt will do it for you.