By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,828 Members | 801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,828 IT Pros & Developers. It's quick & easy.

mail() and To: headers

P: n/a
I'm using the mail() function to send e-mails. The first argument to the
function is the e-mail address the mail will be sent to. I understand this
should just be in the format 'address@domain' and not '"Name"
<address@domain>' and that if I want to specify the name of the recipient as
well as the address of the recipient I should pass it as an addition header.
This works fine locally under Windows and Apache but remotely under Linux
and Apache the resultant raw message has 2 To: headers meaning the client
displays it as being sent to 2 addresses (the same address twice). Am I
doing this correctly? It seems a clumsy way of doing it, especially as
SpamAssassin marks down a message with only an email address in the two
header.

Thanks,
Geoff
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Geoff Soper wrote:
I'm using the mail() function to send e-mails. The first argument to the
function is the e-mail address the mail will be sent to. I understand this
should just be in the format 'address@domain' and not '"Name"
<address@domain>'


I've been using it with the first format without problems.


$ uname -srmo
Linux 2.4.26-1-686 i686 GNU/Linux

$ php -v
PHP 4.3.4 (cli) (built: Mar 27 2004 08:04:22)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

$ cat mailgeoff.php
cat mailgeoff.php
<?php
mail('"Geoff Soper" <ge********@alphaworks.co.uk>',
'test',
'seems to have worked :-)',
'From: Pedro Graca <he****@hotpop.com>',
'-fhe****@hotpop.com');
?>

$ php mailgeoff.php

$

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a
Pedro Graca wrote:
Geoff Soper wrote:
I'm using the mail() function to send e-mails. The first argument to the
function is the e-mail address the mail will be sent to.
Basically, yes. The documentation's examples *imply* that the first
parameter should be a comma-and-space-separated list of one or more
addr-specs, but I can't find where this is explicitly stated.
I understand this should just be in the format 'address@domain'
To send mail to a single mailbox, probably.
and not '"Name" <address@domain>'

Again, that's probably correct; the docs are waffly.
I've been using it with the first format without problems.


OK. But read the Manual's note, which feigns a quotation:

| The to parameter should not be an address in the form of "Something
| <so*****@example.com>". The mail command may not parse this properly
| while talking with the MTA (Particularly under Windows).

"PHP: mail - Manual",
http://www.php.net/manual/en/function.mail.php

And there are related user-comments dated 2003-01-17 and 2003-06-09:

http://www.php.net/manual/en/function.mail.php#28610
http://www.php.net/manual/en/function.mail.php#32848

We're left wondering what the Manual's preferred forms are. Had it
referenced RFC2822, and stated that the first parameter to mail should
be a comma-[and-space-]separated list of addr-specs, our questions
would be answered. As it is, we have to guess.

--
Jock
Jul 17 '05 #3

P: n/a
> Pedro Graca wrote:
Geoff Soper wrote:
I'm using the mail() function to send e-mails. The first argument to the function is the e-mail address the mail will be sent to.

Basically, yes. The documentation's examples *imply* that the first
parameter should be a comma-and-space-separated list of one or more
addr-specs, but I can't find where this is explicitly stated.

| The to parameter should not be an address in the form of "Something
| <so*****@example.com>". The mail command may not parse this properly
| while talking with the MTA (Particularly under Windows).


Reading this excerpt from the manual again, is it the case that any mail
server the message might pass through potentially might have a problem or is
it just the SMTP server my script talks to directly? If it's the latter then
it works so it must be OK for me to use but if it's the former then it's
about taking a chance.

Any suggestion?

Thanks,
Geoff
Jul 17 '05 #4

P: n/a
Geoff Soper wrote:
[From <http://www.php.net/manual/en/function.mail.php>:]
| The to parameter should not be an address in the form of "Something
| <so*****@example.com>". The mail command may not parse this properly
| while talking with the MTA (Particularly under Windows).


Reading this excerpt from the manual again, is it the case that any mail
server the message might pass through potentially might have a problem or is
it just the SMTP server my script talks to directly?


Just the SMTP server your script talks to directly.

Conversations between user-agents and MTAs are private matters. What
happens after that, however, is covered in RFC2821.

RFC2821, Simple Mail Transfer Protocol,
http://www.ietf.org/rfc/rfc2821.txt

--
Jock
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.