Forum Moderators: coopster

Message Too Old, No Replies

mail() problem

after switching hosts

         

4string

1:38 pm on May 20, 2005 (gmt 0)

10+ Year Member



I just moved my php site to a new host. The previous host and the new one are both running the PHP 4.3.11. The sendmail path is the same.

If I use a script that has a mail() function and the address is to an address of the same domain as the site, it works ok. If it is to an outside address, it disappears. Though it returns it was a successful send.

Do I have some security feature enabled that is unknown to me? (A lot is unknown to me. LOL)

Thanks for any help!

dcrombie

1:52 pm on May 20, 2005 (gmt 0)



You need to check the server logs for sendmail.
On *ix they're usually at:

/var/log/mail/mail.log; or 
/var/log/mail.log

4string

2:36 pm on May 20, 2005 (gmt 0)

10+ Year Member



I don't have root access. :(

I am trying to get that from the host.

jatar_k

4:11 pm on May 20, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also is it not getting into the mail account? Maybe it is just being filtered as junk or spam.

4string

4:33 pm on May 20, 2005 (gmt 0)

10+ Year Member



I don't think it's a junk mail problem. It's a new domain and I can send from Horde and the like ok.

It's very frustrating as I have no clue what to even look at.

iceman22

8:56 am on May 24, 2005 (gmt 0)

10+ Year Member



I'm experiencing the exact same problem.

Using mail() worked fine for any address, but sometime in the last few months something happened and I'm only able to send mails to my domain. The mails are being delivered to sendmail, as the function is returning a boolean of true.

It's definitely not a problem with receiving the emails client side. My ISP isn't responding to support emails, and without root access to check the sendmail logs, I'm out of options.

I am however, able to send mails normally using Perl, as below:

open ( MAIL,"¦/usr/sbin/sendmail -t");
print MAIL "To: myname\@gmail.com\n" ;
print MAIL "From: visitor\@hisdomain.com\n" ;
print MAIL "Subject: Comments from Web Form\n\n" ;
print MAIL "What a message!" ;
close ( MAIL ) ;

4string

2:37 pm on May 24, 2005 (gmt 0)

10+ Year Member



I just figured out my problem yesterday. For me it was due to not yet deleting the domains from my old account. I was sending mail to my main email on the old host. The old host server somehow got confused trying to route the mail and the mail disappeared. Deleting the add-on domains on the old host resolved my problem. Hope it fixes yours.

Thanks for the input everyone.

iceman22

9:55 am on May 26, 2005 (gmt 0)

10+ Year Member



I do not have any add-on domains so unfortunately that won't solve my problem.

The fact I an do it in Perl leads me to think something isn't configured properly in PHP.

While the above lines work in Perl, as with mail(), this function wont deliver mails other than to the domain:

function newMail($to,$subject,$message,$headers) {
$mail = popen("/usr/sbin/sendmail -t", "w");
fputs($mail, "To: $to\n");
fputs($mail, "$headers\n");
fputs($mail, "Subject: $subject\n\n");
fputs($mail, $mess);
fclose($mail);
}

andye

10:26 am on May 26, 2005 (gmt 0)

10+ Year Member



I've had a similar problem in the past (in Perl) - it turned out to be connected to the permissions of the user that owned the script.

Ie the script was running as a user with too low permissions in respect of sendmail, afair.

(wouldn't even call this my own $0.02, just $0.01, but I hope it helps)

best, a.

dreamcatcher

7:19 pm on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are your hosts Aventurehost?

They have done the same thing because people have been abusing their servers with mail scripts, so when they upgraded to new servers they changed their settings so that the mail function would only work to domain addresses. Sounds like yours have done the same.

I got around it by using the PHP mailer.

http://phpmailer.sourceforge.net/ [phpmailer.sourceforge.net]

dc

StupidScript

10:03 pm on May 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I, too needed to switch to phpmailer after a server upgrade. It's a little more explicit in its actions than the PHP mail() function. Here's my (redacted) code, after putting
class.phpmailer.php
and
class.smtp.mailer
into my apache root directory, alongside the phpmailer installation folder:

require("class.phpmailer.php");

require("class.smtp.php");

if ($to_email) {

# SEND MAIL

$mail = new PHPMailer();

$mail->IsSMTP();

$mail->Host   = "mail.mydomain.com";

$mail->SMTPAuth = true;

$mail->Username = $phpuname;

$mail->Password = $phppassw;

$mail->SetLanguage("en","/var/www/phpmailer/language/");

$mail->From   = "user@mydomain.com";

$mail->FromName = "User";

$mail->AddAddress($to_email,$to_name);

$mail->AddReplyTo("user@mydomain.com","User");

$mail->Subject = $to_subject;

$mail->Body   = $mail_body;

if(!$mail->Send()) {

echo "Message was not sent <p>";

echo "Mailer Error: " . $mail->ErrorInfo;

exit;

}}

Might be helpful. I had to gather stuff from a couple of locations to put that together.

iceman22

4:14 pm on May 28, 2005 (gmt 0)

10+ Year Member



Thanks for the replies, no luck yet though unfortunately.

PHPMailer was successful for mailing my domain, but recieved this error for other domains:
"Message was not sentMailer Error: Language string failed to load: recipients_failedmyemail@somedomain.com"

The Perl script still works though, it doesnt work if it's called from a PHP script, I get the Hello World I put in it but it doesn't send the mail.

Are there any other ways of using the Perl mail functionality without rewriting my scripts in Perl?