Also, you might try something more like this...
Main Topics
Browse All TopicsHi all,
I have a problem with PHP. I am using the mail function and the format is:
$MailSent = mail($the_user, $the_subject, $the_body, "From: Guy Davis <guy@epicsky.com>\r\nReply
What is happening is the mail recipients are getting mail in the format:
> From: apache@www.domain.com <apache@www.domain.com>
> Subject:
> To: guy@epicsky.com
> Date: Tuesday, November 3, 2009, 3:30 PM
> BODY TEXT
> BODY TEXT
> BODY TEXT
notice how the from address is not the same as the one in the mail statement. How can I track down why this isn't working?
Thanks,
Guy Davis
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Just checking around, here is one of my "from" lines - see if that helps.
I think you can add other fields to the "from" part (it is technically called the additional_headers), separated by those \r\n line breakers.
http://us3.php.net/manual/
Best, ~Ray
I think MIME type and content type are conflicting. Though not sure.
Use the below code. It works for me.
$headers = "MIME-Version: 1.0\r\n";/* Do not change the headers, unless you know about MIME */
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";/*
$headers .= "From: Guy Davis <guy@epicsky.com>\r\n";
$head
$Mail
Hi Guy,
Hope all is well with you and Tim.
$MailSent = mail($the_user, $the_subject, $the_body, "From: Guy Davis <guy@epicsky.com>\r\nReply-T
I'm not sure if you're working on a Linux box or not, but the -f parameter really only works for sendmail, so if you're on a Windows box, or if the sendmail program has been replaced with a different SMTP daemon like Postfix or Qmail, then the -f parameter may not work exactly the same way.
Ultimately, it's probably better to use the PHPMailer v5.1 class:
http://sourceforge.net/pro
Basic example here:
http://phpmailer.worxware.
It circumvents the mail() class and handles email much better. Plus, as your email becomes more complex (if you want to add attachments, HTML-formatted email, "friendly names" for your recipients, etc), it has support for everything.
@guy
Ah, sorry. It's Jonathan Hilgeman.
Sorry - I linked to the wrong example. The example you should try following is this:
http://phpmailer.worxware.
PHPMailer can use different methods to send mail - it can be a wrapper around the mail() function, it can try to communicate directly with sendmail, or it can just speak SMTP directly with the mail server. That error message you got was probabyl because I linked to the example that used the mail() function. You should use the SMTP example instead.
Sorry - I have been away for a while and I am just getting back to this.
"Thanks Ray but I don't see a difference from the format you are suggesting to the one I am using. They are essentially identical." -- I don't think so, or I wouldn't have posted the example that we use here.
Here is what I see as different, with more than just a distinction - different functionality.
Mine:
From: The National Presbyterian Church <KBrinkley@NatPresCh.org>\r\
Yours :
From: Guy Davis <guy@epicsky.com>\r\n
Reply-To: Guy Davis <guy@epicsky.com>\r\n
Content-type: text/htm
If you try simplifying it to just the "From" part of the headers you may find that you're OK on that part of the email message. Then you can try adding more fields into the headers.
HTH, ~Ray
PS: Is PHPMailer better? It may be, depending on how many messages you expect to send. But you will need to get the headers right for that class, too.
Just to be clear, Ray's solution SHOULD work. You should be able to use the mail() function as expected by setting the headers that way. I was simply suggesting PHPMailer since I find it to be easier to use than the mail() function.
On a separate note, the -f parameter is for the envelope header part of the mailing process (when the mailer program sends its "MAIL FROM:" command to the mail server). Usually you don't need to set this, unless you're really trying to get rid of any trace of the original mailing program.
Final note - just for kicks, try replacing your \r\n with \n. Usually this is not necessary, but there are a few mail servers that try to "fix" your carriage returns by replacing \n with \r\n. So if you sent \r\n to begin with, they'll accidentally convert \r\n to \r\r\n, which is invalid and would break your headers.
Nope, haven't tried that, although I think the \r\n "fix" is something that the SMTP daemon does, not PHP, and since PHP_EOL is specifix to the PHP installation... -shrug- I'm not sure. I've only come across that \r\n thing once and that was several years ago, on someone else's server. I could be all wrong about this suggestion, but I figured I'd throw it out there, just in case.
Business Accounts
Answer for Membership
by: Ray_PaseurPosted on 2009-11-04 at 08:12:39ID: 25740792
Who is your hosting company?