I’m trying to send email from PHP, and although it’s working, I’m noticing that I’m getting a lot of extra stuff in the “from” part of the email. The extra stuff, I’m assuming, is
information from my server?
For example, if $from = "myname", instead of "myname" only coming through in the email from field as is, I get something like:
Here is my PHP I’m playing with, the important part being my $from var:
$from = "myname";
mail($to,$formSubj,$formMssg,$from);
Honestly that’s all I have, nothing more or less (as far as the $from is concerned). How can I clean this up or make it so that only the plain value of $from, which is in this case "myname", comes out?
The 4th parameter of the mail function doesn’t work this way. It expect header information. To achieve what you want to do use:
You shouldn’t use a lonely
mynameeither. You need a valid email addess string:myname <no-reply@test.com>orno-reply@test.com. If you just putmyname, PHP will try to interpret it as an email address. That’s why you’re gettingmyname@p3nlhg.phx3.secureserver.net.p3nlhg.phx3.secureserver.netmust be the hostname of your server.A nice thing about the header parameter is that you can use it to specify other less common fields. e.g.:
Notice that you need to place a carriage-return/line-feed (
\r\n) at the end of each header attribute. A simple line feed will not work.