PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousldap_unbindezmlm_hashnext
Last updated: Tue, 03 Sep 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Hungarian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

XLIX. Funzioni di Mail

La funzione mail() consente di inviare mail.

Direttive di configurazione per Mail

SMTP string

Nome DNS o indirizzo IP del server SMTP che PHP sotto Windows deve usare per spedire posta elettronica con la funzione mail().

sendmail_from string

Quale campo "From:" devono avere i messaggi inviati da PHP sotto Windows.

sendmail_path string

Dove trovare il programma sendmail, solitamente /usr/sbin/sendmail oppure /usr/lib/sendmail. configure cerca di trovare il file e lo imposta di default, ma se non riesce a localizzarlo, lo si pu� impostare qui.

I sistemi che non usano sendmail devono impostare questa direttiva al wrapper che i rispettivi sistemi di posta offrono, se esistenti. Per esempio, gli utenti di possono normalmente impostarla a /var/qmail/bin/sendmail o /var/qmail/bin/qmail-inject.

qmail-inject non richiede nessuna opzione particolare per processare correttamente le mail.

Sommario
ezmlm_hash -- Calcola il valore hash che occorre a EZMLM
mail -- Invio mail
User Contributed Notes
Funzioni di Mail
add a note about notes
10-Nov-2001 09:35
For Windows users, you can likely set the SMTP directive in the php.ini configuration file to your isp's SMTP mail server - the same as you use for outgoing mail in your email client (Eudora, Outlook, etc.) . However, check with your ISP before doing this!

eg
SMTP = mail.your_isp.com

[email protected]
31-Jan-2002 03:26

the 'sendmail_from' string is the default 'from' address supplied with any outgoing mail if no other 'from' address has been supplied in the header section of the mail() function. In other words, setting the 'from' address in the mail() function overrides this setting.
19-Feb-2002 01:23
After guessing about an hour I found out that for my qmail installation only the following php.ini setting works:

sendmail_path =/var/qmail/bin/qmail-inject

Woutjan Branderhorst.

[email protected]
23-Feb-2002 12:03

Check out Zend.com's code gallery under EMAIL, look for SMTP.

with the new class you can specify different hosts (with respective l/p) anytime you wish.

good for guys who hasn't got the mail() enabled (i think) but can at least open sockets.

again, i'm green at this, might be incorrect.

[email protected]
03-Apr-2002 05:58

Hi there,
here is a little snippet that can be used in your mail script in order to check if the mail was really sent from the domain the message originated from:

// array for allowed domains (lower case please)
$referers = array('php.net', 'www.php.net', 'us2.php.net');

// add upper case referrers
$size = sizeof($referers);
for($i = 0; $i < $size; $i++){
$referers[] = strtoupper($referers[$i]);
}

// check referers
for($i = 0; $i < sizeof($referers); $i++){
if(substr($HTTP_SERVER_VARS['HTTP_REFERER'], 7, strlen($referers[$i])) == $referers[$i]){
$bad_referer = FALSE;
break;
}
else{
$bad_referer = TRUE;
}
}
if($bad_referer){
header('Location: );
exit;
}

I added the upper case domains, since once in a while surfers tend to write in all-caps.

Hope that helps someone :-)

DrTebi

[email protected]
05-Apr-2002 02:28

Linux
Known situation mail() not work, but why ???

Try send a simple mail from shell
root@alpha:~# sendmail [email protected]
strange error ???

collect: Cannot write ./dfg35A7vav022304 (bfcommit, uid=XXX, gid=XXX): Permission denied

queueup: cannot create queue temp file ./tfg35A7vav022304, uid=XXX: Permission denied

Don't mess with permissons on /var/spool
/var/mail /var/spool/mqueue
Just set them follow the instructions from sendmail readme
It seems that when sendmail runs not like a daemon ( without -bd or -bD options ) it doesn't use corect QueueDirectory from /etc/mail/sendmail.cf

The solution is

set this line in php.ini
;For Unix only.You may supply arguments as well (default:'sendmail -t -i').

sendmail_path="/usr/sbin/sendmail -t -i -OQueueDirectory=/var/spool/mqueue/"

That's all. mail() now work fine :)))
Hope this will save up somebody's time, because i spent a lot of hours in digging and tearing my hair (and my mother will colapse if she hear what a words i use :)))

12-Apr-2002 03:35
As noted above sendmail_from is only used on MS Windows, to change the default sender on unix you must add -f to sendmail_path. For example in a <VirtualHost> directive:
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f [email protected]"

would set the default return-path for mail from that virtual host.

[email protected]
20-May-2002 09:21

Dear all,

Setting up a system which will ask a new member to confirm he asked for it
by mailing him I experienced a problem. If a new member fills in a Hotmail
e-mailaddress he will receive my mail in his Junk Mail directory.

Many tips I found where telling te configure the php.ini on my server but
that is not enough. I use Apache on a Win32 so some things will be different
for you Linux people but the problems I experienced do not have anything to
do with that I believe.
But, configure your php.ini setting the mail functions, for Win32:

SMTP = mail.yourisp.com
sendmail_from = [email protected]

Now the most important.
When using mail() you should insert headers, and not just a few!!!
I give you an example I'm using.
Very important is also to include the ' To: ' header. I forgot this and when
I put it in my code Hotmail didn't refuse my e-mails anymore. Only when
people have there Junk Mail listed as "Exclusive". But when configured
"High" it will go ok.

Here the example:

$myname = "Me Myself";
$myemail = "[email protected]";

$contactname = "Mister Contact";
$contactemail = "[email protected]";

$message = "hello from happy me";
$subject = "A mail not refused by Hotmail";

$headers. = "MIME-Version: 1.0\r\n";
$headers. = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers. = "From: ".$myname." <".$myemail.">\r\n";
$headers. = "To: ".$contactname." <".$contactemail.">\r\n";
$headers. = "Reply-To: ".$myname." <$myreplyemail>\r\n";
$headers. = "X-Priority: 1\r\n";
$headers. = "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: Just My Server";

mail($contactemail, $subject, $message, $headers);

I hope this helped someone.

Godfried van Loo
The Netherlands

[email protected]
26-May-2002 02:30

mail will NOT work if your system doesn't have
a /bin/sh (like in chroots...)

just take some time to figure it out ;)

29-May-2002 01:15
I use qmail, and have found that mail() will return TRUE even if there is no valid email address in the To parameter. If you're having problems getting mail() to work with qmail, double-check that the output from your script produces a valid email message before looking further!
[email protected]
03-Jun-2002 04:11

i have noticed that the mail() doesnt work if you define some headers in a variable ($headers) and also within the mail( ..here.. ). this causes a conflict for some reason
example...

$headers = "MIME/TYPE blah blah blah";
$headers = "Cc: [email protected]";

mail("$headers", "From: [email protected]");

i hope this helps

[email protected]
03-Jun-2002 04:12

i have noticed that the mail() doesnt work if you define some headers in a variable ($headers) and also within the mail( ..here.. ). this causes a conflict for some reason
example...

$headers = "MIME/TYPE blah blah blah";
$headers = "Cc: [email protected]";

mail("$headers", "From: [email protected]");

i hope this helps

[email protected]
04-Jun-2002 02:03

Hi!

I'm using this:

mail($friend_email, "A friend wishes you to see this!", "$message\n\nURL: $url\n\nYour friend, $you_name\n<a href=\">$you_email</a>", "From: $you_email");

I want to get a linked email adress of the $you_email adress. Since this is not html, I know this is not correct. Do I need to use $headers ? or can I send the message as html?

What do you recommend me to do?

[email protected]
06-Jun-2002 03:50

use these headers to send in html form

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

[email protected]
10-Jun-2002 09:40

Hi..
I'm using this
mail($to, $subject, $message, $headers);
when I run the program the following message occure
Warning: Failed to Connect in C:\apache\htdocs\mail\mail2.php
please tell me what is the problem?
what should I do?

[email protected]
12-Jun-2002 04:07

If you have downloaded an email via POP connection, ex.:
$complete_email ="
Date: Wed, 20 Jun 2001 20:18:47 -0400
From: "Sergio Paternoster" <[email protected]>
To: "My Users" <[email protected]>
Subject: Hello from Sergio!
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello from Sergio!
";
and want to forward it to another email address, just change the To: field into the encoded downloaded email and then use

mail("", "", "",$To_changed_complete_email);

[email protected]
26-Jun-2002 03:08

If some of your mails cannot be received by some people, you might have the following problem:

Some mailservers block messages with more than 1024 Characters in a single line.

Solution: just add a simple linebreak (\n) after the last space before each character 1024

You could possibly use wordwrap() for this...

[email protected]
27-Jun-2002 10:53

having a little problem with the mail function. trying to generate several emails to addresses submitted by a user and i need to tell if any of these emails get returned as undeliverable. they do not, however get returned to the "reply to" address nor the "from" address. where would the returned message get sent?
[email protected]
11-Jul-2002 12:35

in the excellent 'header' example:
[email protected]
20-May-2002 02:21

I find it better to use:

mail("", $subject, $message, $headers);

because you are already setting the TO: in the headers. If you put the $contactemail, you will see two names on the TO line on the email separated by ;

also, if it's not painfully obvious, use:
"Content-type: text/plain"
to get regular text vs. html text.

11-Jul-2002 08:06
Took some digging to find how to set the mail server port number as the typist of the documention above forgot to finish typing the Mail Configuration Directive "smtp_port".
[email protected]
15-Jul-2002 05:41

deseo enviar de un fromulario web a varios direcciones de mail a la ves la informaci�n recibida.
[email protected]
15-Jul-2002 08:07

I have a problem. Everywhere is writing "It's simple", but I can't find how to do it:
Send a HTTP massage to another serwer using POST method (one var) without any form (it has to be authomatic, without any user). I wrote e-shop in PHP and I'm looking for answer in PHP.
Please help me!!!

[email protected]
15-Jul-2002 10:15

Re: [email protected]
To send a POST to another server with php, i would either:
1) open a socket to that remote server, and write the HTTP POST request...
-create socket
-write ("POST <uri> HTTP/1.0\n")
-write ("...\n")
-write("Content-type:application/x-www-form-urlencoded\n"
-write("Content-length:".strlen($post_data."\n")
-write("\n")
=write($post_data."\n")

2) Use CURL lib, like ...
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$remote_host)
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data)
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$page = curl_exec ($ch);

to see what all those CURLOPT mean go to

I hope this helps !
David

[email protected]
09-Aug-2002 06:29

Solution to massmailing timeout:
Unsafe solution is to change the timeout properties in php.ini
The better solution is to create separate email object run through window command prompt (in windows) or separate shell function (in unix) that will run itself separately until termination.
[I found php to run faster in a shell/command prompt]

[email protected]
16-Aug-2002 11:46

If you need to send an e-mail with an html content and the same e-mail have Bcc headers.
Place the Bcc (and why not also Cc) at the end of your additional headers. Otherwise, people receiving the email in copy may have the html code in their screen. The one who are designed as main recipient will not have this problem.

Explanation :
=========
The e-mail headers are broken when the PHP parser delete the Bcc line (Removed cause hidden, obvious !).

Example :
=======

This is bad

$header = "From: \"".addslashes($sender_name)."\" <".$sender_email.">\r\n";
$header .= "Reply-To: ".$sender_email."\r\n";
$header .= "Cc: ".$other_email."\r\n";
$header .= "Bcc: ".$another_email."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$header .= "X-Priority: 1\r\n";
$header .= "X-Mailer: PHP / ".phpversion()."\r\n";

The following is good

$header = "From: \"".addslashes($sender_name)."\" <".$sender_email.">\r\n";
$header .= "Reply-To: ".$sender_email."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$header .= "X-Priority: 1\r\n";
$header .= "X-Mailer: PHP / ".phpversion()."\r\n";
$header .= "Cc: ".$other_email."\r\n";
$header .= "Bcc: ".$another_email."\r\n";

Sorry for my bad english. :-)

Redy Ramamonjisoa
<[email protected]>

[email protected]
19-Aug-2002 07:43

I had a problem with the outgoing email from PHP: The emails were going OUT but not being recieved by SOME users.

Specifically, users with accounts within my own ISP were fine (COX.NET), my .NAME account was OK, and others. AOL users got NOTHING as well as some other users.

The problem was was with PHP.INI settings. Notice the default setting:

sendmail_from = [email protected] ; for Win32 only

This affects the "return path" header (on my system anyway) REGARDLESS of the From header entry. Apparently some anti-spam filters look at the return path to see if it is legit and, if not, drop the message.

If you leave this as is it will work fine... for SOME mail transports, but not all!! For it to work properly, I had to configure it to be an email address within the domain of my ISP. Note that I also have the SMTP server set to my ISP's main outgoing SMTP server. Apparently, any address will work as long as it is properly formatted and from the domain of the SMTP server.

My setting now reads similar to:

sendmail_from = [email protected] ; for Win32 only

I haven't verified it works in all cases, but it works at least for AOL. I'm fairly confident it will work for all my users, I'll try to remember to post more info if I find out anything else.

BTW: I didn't have to change the \r to \r\n with my configuration (XP/IIS5), but I have had trouble with that in other platforms (e.g. NT4/IIS4). You might want to look at that as well.

[email protected]
21-Aug-2002 03:11

This is an example 4 sending german umlaute - but it works 4 other special character settings, 2.

mail("[email protected]","Subject",
"Content",
"Mime-Version:1.0\nContent-Type: text/plain; charset=\"iso-8859-1\nContent-Transfer-Encoding: 8bit\"");

Regards,

Dipl.Inf. (FH) Bernd Schwaegerl
Mueller-Knoche GmbH, Systemhaus fuer EDV-Loesungen

[email protected]
23-Aug-2002 01:13

When you got a "Server Error" you not allowed to send a EMail with you return address or to a specified EMail address.

Test it with "telnet (smtp server) smtp" and you get a 550 Relaying is prohibited Error.

regards

[email protected]
05-Sep-2002 10:20

[email protected]
20-May-2002 03:21

For anyone who uses the example posted by '[email protected]' above, '$header. =' is invalid and should be '$header.= '.

[email protected]
06-Sep-2002 07:53

How to detect a bounce email

1. make sure the email you send out have the header
"Return-Path: [email protected]\r\n",
&
"Return-Receipt-To: [email protected]\r\n"

2. setup this detect-bounce mail account at your mail server

3. redirect the incoming mail from this email account to your php script (check your mail server doc on how do this)

4. your php script will then be able to process the incoming email in whatever way you like, including to detect bounce mail message (use regexp search).

Note that the mail will be not be store after the mail server has redirect to your script. If you want to store it, you need additional code in your script

Hope the above help

Steven Lim
IT Consultant (www.Edinburgh-Consulting.com)

add a note about notes
previousldap_unbindezmlm_hashnext
Last updated: Tue, 03 Sep 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Fri Sep 6 12:35:50 2002 CEST