PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousldap_unbindezmlm_hashnext
Last updated: Thu, 18 Jul 2002
view this page in Printer friendly version | English | Chinese | Czech | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

L. Mail functions

The mail() function allows you to send mail

Mail Configuration Directives

SMTP string

Used under Windws only: DNS name or IP address of the SMTP server PHP should use for mail sent with the mail() function.

SMTP int

Used under Windws only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25. Only available since PHP 4.3.0.

sendmail_from string

Which "From:" mail address should be used in mail sent from PHP under Windows.

sendmail_path string

Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject.

qmail-inject does not require any option to process mail correctly.

�ndice
ezmlm_hash -- Calculate the hash value needed by EZMLM
mail -- send mail
User Contributed Notes
Mail functions
add a note about notes
10-Nov-2001 08: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


31-Jan-2002 02: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 12: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.


22-Feb-2002 11: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.


03-Apr-2002 04: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


05-Apr-2002 01: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 02: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.


20-May-2002 08: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


26-May-2002 01: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 12: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!


03-Jun-2002 03: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


03-Jun-2002 03: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


04-Jun-2002 01: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?


06-Jun-2002 02: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";


10-Jun-2002 08: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?


12-Jun-2002 03: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);


26-Jun-2002 02: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...


27-Jun-2002 09: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?


28-Jun-2002 05:15

i don't understand this error :

Warning: Server Error in
C:\Inetpub\cris\theatre-contemporain\tintasfrescas
\news\news.php3 on line 81

line81 :
if (mail($to, $subject, $body, $header))
{
$mesg = $phrase5;
}
else
{
$mesg = $phrase12;
}

What's the problem ??

Please note that my server is running under windows 2000.

Thanks a lot


01-Jul-2002 03:12

Hey, can anyone tell me how to set the path to sendmail? I'm running
Indigomail ( sendmail for windows ) and I got it to send mail with perl
... I'm just unfamiliar with the syntax for the php mail() function ...
Here's what i have:

    $sendmail = "D:\\inetpub\\scripts\\sendmail.exe";
    $To = "[email protected]";

    if (mail($To, "Tech Maintenance Request from $name",
"Tech Maitenance Request\n\n $name $room - $building:\n\n
Description\:\n $problem \n", "From: $email",
"sendmail_path: $sendmail")) {
    print "Could not complete your request,
<b>$sendmail</b>";

    } else {

    print "The request was successfully mailed to $To";

    }


03-Jul-2002 01:06

hello... I want to use the mail() funtion, but somehow my code didn't work.

I have my ISP is Directv with SMTP : smtp.directvinternet.com

what do I need to do with the above SMTP in order to get my mail()
function to work ? I am using Window 2K server.

I already try to reconfigure my php.ini to:

smtp: smtp.directvinternet.com

What else do I need.  I am a newbie.

Thanks!

09-Jul-2002 09:02
Can anyone tell me that how to check if the domain of the input mail
address is really exist by a PHP script?
Thank you & have a good day!!


09-Jul-2002 09:07

Can anyone tell me how to check the domain of a mail address is really
exsit by PHP script?

Is there any function for it?

Thank you & hava a good day!


10-Jul-2002 11: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 07: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".


12-Jul-2002 08:25

Please note that the mail() function is pretty slow, so if you are planning
to develop a script which has to be able to send a few thousand emails or
more, you will need to use set_time_limit() in order to make sure the
script doesn't time out.
Also, you might want to create your own mailing function, which could save
in time.


15-Jul-2002 04:41

deseo enviar de un fromulario web a varios direcciones de mail a la ves la
informaci�n recibida.


15-Jul-2002 07: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!!!


15-Jul-2002 09: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


16-Jul-2002 10:03

Hi there,

Aparently mail() function doesn't offer a feasible way to confirm if the
message was correctly processed by the mail server (was actualy sent to
the TO address). Does anybody have a solution for this (verifying if the
message was really sent to the destination email)?

Thanks,

CB


16-Jul-2002 10:34

i have a form that works perfectly untill i add the mail function, which is
really the whole point of me using it. it's an affiliate application form,
pretty simple really, now what i need to do is send the info that the user
fills in the from to me, to do this did this:  
<?
// Sets the message that will be in the 
// email to me, all it does is posts me the 
// values of the input boxes etc
$Email_Message="$NAME $EMAILi $URLi $COMMENTS $HITS_PER_DAY
$NEW_AFFILIATE $CHANGE_URL $OTHER";
mail ("[email protected]","Affiliate
Application","$Email_Message");
?>
it just wont work and i dont know why, originally i had the information in
$Email_Message just in the message box but it didnt work so i tried this
but i just cant make it work


18-Jul-2002 07:49

On July 12, "topxse" wrote:

> Please note that the mail() function is pretty slow, so if you are
planning
> to develop a script which has to be able to send a few thousand
emails or
> more, you will need to use set_time_limit() in order to make sure the
> script doesn't time out.
> Also, you might want to create your own mailing function, which could
save
> in time.

I am having this very problem: sending out just one message takes over 80
seconds.  (I timed it with microtime().)  How do you create your own
mailing function?  Is there a website I can go to to find out about this? 
Speed is very important in this script.

I'd appreciate any help you can give me!

Ben
. . . . . . . . . . . . . . . .
Ben Kazez


22-Jul-2002 06:38

I'm having problems sending out around 3000 emails... I get through about
250 and it times out, and leaves my mail spool full.  Has anyone found a
good script for mass emailing?


24-Jul-2002 10:28

Same problem here with mail().  Don't believe that I experienced it until I
updgrade PHP > 4.0.6 on the RaQ4, but that could just be me.

PHP = Patch, Headaches, Patch

Here's an answer to the valid email address question.  It's adapted from
code I found on the net somewhere.

if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*
    @[a-z0-9-]+([\.][a-z0-9-]+)+$",$email)) { 
  $err_msg="Invalid Email";
} 
list($user, $domain) = split("@", $email, 2);
if (! checkdnsrr($domain, "MX")) {
  $err_msg = "Email server does not exist.";
}
return $err_msg;

add a note about notes
previousldap_unbindezmlm_hashnext
Last updated: Thu, 18 Jul 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Fri Jul 26 16:06:58 2002 CEST