PDA

View Full Version : PHP mail


Carlos
12-04-2004, 11:55 AM
What I need to do to make the PHP mail function work?

I’m testing my new server before migrate the site. And can’t manage to send an email through a PHP script there.

The code is the most basic possible:
<?php mail('mail@domain.com', 'Subject', 'Hi!'); ?>
Of course I’m using a real e-mail in the code, not the mail@domai...

This code works on my old server and on my local machine. But does nothing on the Sago-Interworx box. Only a blank screen with no errors.

I tried to force some errors, but my new server shoes no PHP errors. Even if you rename the function to a non existing name like mailxxx or something, it doesn’t show an error message.

My php.ini (I never touched it) shows:

error_reporting = E_ALL & ~E_NOTICE
And

[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
Also, I never created an e-mail under the SiteWorx account, as I have no DSN pointing to my server for now.


Why I can’t send e-mails using PHP?

Why I get no error messages?
:confused: :confused: :confused:

Thank you.

IWorx-Paul
12-04-2004, 03:03 PM
The mail is probably getting sent to the mail queue, but not making out of the server for some reason. Check the log file /var/log/send/current when you try to send an e-mail via PHP, and see if there are any corresponding messages in the log file.

Carlos
12-04-2004, 04:33 PM
Thank you Paul.

My /var/log/send/current log file is 39k of the same error message again and again.

Here are the last lines:

@4000000041b225070c74ca14 starting delivery 341: msg 7178840 to local iworx@server1.sagonet.tld
@4000000041b225070c756654 status: local 1/10 remote 0/255
@4000000041b225070ca1bde4 delivery 341: deferral: Unable_to_chdir_to_maildir._(#4.2.1)/
@4000000041b225070ca25254 status: local 0/10 remote 0/255
@4000000041b2271407e51864 starting delivery 342: msg 7178876 to local iworx@server1.sagonet.tld
@4000000041b2271407e66854 status: local 1/10 remote 0/255
@4000000041b227140812007c delivery 342: deferral: Unable_to_chdir_to_maildir._(#4.2.1)/
@4000000041b2271408127d7c status: local 0/10 remote 0/255
@4000000041b2272407f52d94 starting delivery 343: msg 7178879 to local iworx@server1.sagonet.tld
@4000000041b2272407f669fc status: local 1/10 remote 0/255
@4000000041b2272408225044 delivery 343: deferral: Unable_to_chdir_to_maildir._(#4.2.1)/
@4000000041b227240822d8fc status: local 0/10 remote 0/255
@4000000041b2294c031e60c4 starting delivery 344: msg 7178843 to local iworx@server1.sagonet.tld
@4000000041b2294c031eddc4 status: local 1/10 remote 0/255
@4000000041b2294c034b2d84 delivery 344: deferral: Unable_to_chdir_to_maildir._(#4.2.1)/
@4000000041b2294c034bb254 status: local 0/10 remote 0/255

Any clue?

timryberg
12-05-2004, 07:43 PM
Check and see who owns the directory

/home/<username>/var/<domain>/mail/<mailbox>/Maildir

It needs to be

owner: vopomail
group: <username>
chmod: 700

You may have done like I did a couple days ago and chmodded everything in /home/<username> to username:username

Just a thought.

Tim

Carlos
12-10-2004, 09:01 AM
Thanks Tim.

Only to close the thread, the problem about PHP error messages was pure dumminess. All ok now.

About the qmail problem, I still don't know what Unable_to_chdir_to_maildir means, but I am able to send e-mails now.

timryberg
12-10-2004, 10:31 PM
Thanks Tim.

Only to close the thread, the problem about PHP error messages was pure dumminess. All ok now.

About the qmail problem, I still don't know what Unable_to_chdir_to_maildir means, but I am able to send e-mails now.

It means that the user who was running (the mail user) could not change to that directory, why I thought it was a permission problem.

Glad things are working for you now.

Tim

Carlos
12-10-2004, 10:40 PM
Thanks again Tim.

RWF
08-24-2005, 10:30 AM
Please bare with me as this is the first time I am trying to email using PHP.

The simple example Carlos provided works fine for me:

<?php mail('mail@domain.com', 'Subject', 'Hi!'); ?>

It sends an email to the address from iworx@server1.customer.com


But can someone please enlighten me why the below code, pasted from a webpage tutorial, fails to send out an email:

$mail_to=$bt_limitedtextarea3; // Contains recipient's email address
$mail_from="Webmaster@mydomain.com";
$mail_sub="Email Test";
$mail_mesg="Hello World!";

mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from");

Expert from my php.ini:

[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =


Thanks!

IWorx-Dustin
08-24-2005, 11:12 AM
Hi RWF-

This may sound silly, but have you checked the basics?
i.e. what does the $bt_limitedtextarea3 variable contain?
does mail() return true or false?
Do you have open and close php blocks at the beginning and end of your php file?

--Dustin

RWF
08-24-2005, 11:26 AM
Hi RWF-

This may sound silly, but have you checked the basics?
i.e. what does the $bt_limitedtextarea3 variable contain?
does mail() return true or false?
Do you have open and close php blocks at the beginning and end of your php file?

--Dustin


Yes it sure sound silly :)

1) The recipient email address as noted in the code comment!
2) False
3) Yes

As I said the simple example works, but when replaced by the mail code line containing more parameters, it does not. It seems to be when I add the "From" part that it fails to send.

IWorx-Dustin
08-24-2005, 11:41 AM
Heh, speaking of sillyness (as pointed out by Socheat)-

From the mail() reference on php-
http://us3.php.net/manual/en/function.mail.php

Multiple extra headers should be separated with a CRLF (\r\n)

From the code -> "From:$mail_from/r/nReply-to:$mail_from"

You appear to have reversed the slashes, /r/n :)

--Dustin

RWF
08-24-2005, 11:52 AM
Heh, speaking of sillyness (as pointed out by Socheat)-

From the mail() reference on php-
http://us3.php.net/manual/en/function.mail.php

Multiple extra headers should be separated with a CRLF (\r\n)

From the code -> "From:$mail_from/r/nReply-to:$mail_from"

You appear to have reversed the slashes, /r/n :)

--Dustin


Damn I can't even trust a php tutorial site anymore :) http://www.smartwebby.com/PHP/emailsending.asp

Guess that's what you get from copying and pasting huh?

Thanks!