mail questions

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
  I haven't used php to send mail yet and have some questions.

I see that you can add headers, and these days it is essential to have a
real "from".

  But I see you can also do this:

mail('', 'the subject', 'the message', null,

   Does that only work with sendmail and how can you tell what the MTA
(is that right) is?

   Also, how would you include a BCC or Reply To with that?

On a related note, what's with CR LF I see in the examples. I see there
are some issues with the CR, can I simple do this?:

From: some_from
BCC: some blind copy

and expect that to work?


Re: mail questions

Quoted text here. Click to load it

Hey here's some help.

With the PHP mail() function the From MUST be included either in the
php.ini file or in the headers section otherwise it returns a warning.

Separate headers are separated by CRLF in the form of "\r\n" for

    $headers = "From:" . "\r\n" . "Cc:" . "\r\n" . "Bcc:" . "\r
\n" . "";

Note: If messages are not received, try using a LF (\n) only. Some
poor quality Unix mail transfer agents replace LF by CRLF
automatically (which leads to doubling CR if CRLF is used). This
should be a last resort, as it does not comply with RFC 2822.

the mail() would then be something like:
    mail($to, $subject, $message, $headers)

I hope that helped if more assistance is needed check out PHPs website
they have very useful documentation:

Re: mail questions

*** Jeff escribió/wrote (Thu, 24 Jul 2008 09:27:37 -0400):
Quoted text here. Click to load it

If I'm not wrong, it works with Sendmail *and* Sendmail-compatible MTAs
such as Postfix or Qmail. But you must be aware that -f sets the
Return-Path address, not the From header: they're different things.

Quoted text here. Click to load it

These are regular headers: just append them to the fourth parameter of

mail('', 'the subject', 'the message',

Quoted text here. Click to load it

Short answer: yes. Specs say that e-mail should use \r\n but \n tends to
work in practice and I've even seen \r\n failing some times...

Just be careful with $header; if extra line feeds get added, headers will
jump to the message body.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor en cubitos:

Re: mail questions

On Thu, 24 Jul 2008 19:03:12 +0200, Álvaro G. Vicario wrote:
Quoted text here. Click to load it

And you need both, not necessarily set to the same thing. The From: can
go to the email address for someone to answer questions, the From_ needs
to go to someone (or some process) that handles undeliverable mail.
Neither should be set to a "noreply" or invalid or nonfunctional
address. Some anti-spam measures will check either or both for

36. I will not imprison members of the same party in the same cell block, let
    alone the same cell. If they are important prisoners, I will keep the only
    key to the cell door on my person instead of handing out copies to every
    bottom-rung guard in the prison. --Peter Anspach's Evil Overlord List

Re: mail questions

Peter H. Coffin wrote:
Quoted text here. Click to load it

Can you talk a bit more about the Return Path? How would you set that as
a header?

   And, I understand that some mail clients look at something like a
return path and this should be set somewhere on the site for the server
to check. I'm quite hazy on all this and any clarification would be a
huge help.

Quoted text here. Click to load it

Site Timeline