cant send mail using mail()function

ullalla

Well-Known Member
Jan 20, 2006
192
0
166
I am trying to send mails to yahoo and gmail to from my site but the mails are not delivered.And if I use the test account from my site then it is delivered. The script I am using as:
<?php
$to = "[email protected]";
$fromname = "[email protected]";
$subject = "Testing EMail";
$mailheaders ="From: test <[email protected]> \n";
$msg = "This is a test message from test.\n";
mail($to, $subject, $msg, $mailheaders);
echo "Done!";
?>


Please let me know if there is anything wrong.
 

Zion Ahead

Well-Known Member
Nov 10, 2006
347
0
166
Same problem here...

Using php 4.4.4 (phpsuexed NOT enabled)
disabled "Prevent the user "nobody" from sending out mail"

Using Chirp's EXIM ACL

How do I correct this?
 

aralis

Member
Dec 22, 2006
15
0
151
Lubbock TX
I was going to suggest disabling "Prevent the user "nobody" from sending out mail" via WHM for ullalla. Are you sure that your problem is not related to the EXIM ACL you are running? Have you tried it before you installed the ACL?
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
Assuming mail() is not in the disable_functions list in PHP.INI,
you are lacking 1 additional parameter to your mail function ...

Code:
mail($to, $subject, $msg, $mailheaders, "-f $fromname");
Many of the large email services automatically filter out messages sent
from user "nobody" assuming those messages to be spam.

It would also be a good idea to add an SPF record to your domain DNS record
if you don't already have an SPF record.
 

sparek-3

Well-Known Member
Aug 10, 2002
2,152
268
388
cPanel Access Level
Root Administrator
What do the exim logs show when you attempt to send a message in this fashion? Adding the -f flag is optional, but if you are running PHP as an Apache module, then some hosts may reject the message because the envelope sender will be [email protected] and some e-mail providers block this. Really the only course of action you have is to check the exim logs and see what it says. If it shows the message as being sent and delivered, but it still does not arrive at the destination's mailbox, then there's likely some type of filtering being done at the destination server after the message is accepted. The administrators of the destination server would be the only ones that could investigate that.

One other thing I see:

PHP:
$mailheaders ="From: test <[email protected]> \n";
There appears to be a space between the > and the carriage return. Have you tried removing that and see if that helps. I'm not sure if that would cause any problems or not. I've always used \r\n as the carriage return for additional headers. I'm not sure if that is necessary or not, but its what I normally use.

PHP:
$mailheaders ="From: test <[email protected]>\r\n";
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
Adding the -f flag is optional, but if you are running PHP as an Apache module, then some hosts may reject the message because the envelope sender will be [email protected] and some e-mail providers block this.
Congratulations! You just said WHY they should actually use the "-f" flag!

Many mail service providers will broadly block "[email protected]" or "[email protected]" when sent using mail()
without the "-f" flag but will go ahead and allow the messages if you use that parameter.

Personally though, I would use SuPHP and then it's not an issue at all anymore! ;)


PS: Yes, you are correct on the carriage returns. All scripts should use "\r\n" for mail carriage returns.
 
Last edited:

Zion Ahead

Well-Known Member
Nov 10, 2006
347
0
166
It appears that

/home/user/public_html/cgi-bin/ FormMail.cgi

is calling /usr/sbin/sendmail -i -t as the mailprog.

However when executing sendmail at the command line, we're getting a segmentation fault and core dump.

[email protected] [/home/user/public_html/cgi-bin]# /usr/sbin/sendmail -i -t
Segmentation fault (core dumped)

[email protected] [/etc/mail]# ls -al
total 16
drwxr-xr-x 3 root root 4096 Dec 14 15:28 ./
drwxr-xr-x 60 root root 8192 Dec 26 15:33 ../
drwxr-xr-x 2 root root 4096 Dec 14 15:28 spamassassin/

Can someone please explain the fix for this?
 

xprt5

Well-Known Member
Apr 6, 2003
72
0
156
Houston
rename /usr/sbin/sendmail to /usr/sbin/old-sendmail and run /scripts/eximup --force

eximup will replace the sendmail binary with the correct one that will work.
 

codegirl42

Well-Known Member
Mar 9, 2006
93
0
156
I have the "Prevent user nobody from sending mail...."....

Is this the reason why "Email All Users" doesnt work in WHM?

And if so, is there a work around for Email All Users?
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
I have the "Prevent user nobody from sending mail...."....

Is this the reason why "Email All Users" doesnt work in WHM?

And if so, is there a work around for Email All Users?
You can only use the "prevent user nobody" option if you have setup phpSuExec or SuPHP ...

Otherwise, you just effectively disabled the mail function for all web scripts because
servers not running phpSuExec or SuPHP will execute all scripts as user "nobody"!