Forum Moderators: bakedjake

Message Too Old, No Replies

Help with sendmail and php mail() setup

Sendmail help and PHPmail()

         

jgalba

4:58 am on Aug 5, 2004 (gmt 0)

10+ Year Member



I have a new dedicated server and I cannot get the mail() function to work from my PHP scripts. Everything else seems to work great but I cannot send mail from a PHP script. Please help? I have a linux,Red Hat Enterprise, Ensim Basic dedicated server at EV1.

NickCoons

8:23 am on Aug 5, 2004 (gmt 0)

10+ Year Member



I had the same issue. My old server worked fine.. and when I migrated the site to its own dedicated box, this function stopped working even though sendmail was working just fine. I also noticed that PHP's mail() function is very slow. I run a mailing list, and I created a web-based system to manage and deploy all of these emails.

I ended up creating my own function to replace PHP's mail() function, which A) works on my new system, and B) is many times faster than PHP's mail() function. Here it is, in case you'd like to use it. It uses sockets to connect directly to the SMTP server of your choice:

function SendMail($ToName, $ToEmail, $FromName, $FromEmail, $Subject, $Body, $Header)
{
$SMTP = fsockopen("smtp.sitename.com", 25);

$InputBuffer = fgets($SMTP, 1024);

fputs($SMTP, "HELO sitename.com\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "MAIL From: $FromEmail\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "RCPT To: $ToEmail\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "DATA\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "$Header");
fputs($SMTP, "From: $FromName <$FromEmail>\n");
fputs($SMTP, "To: $ToName <$ToEmail>\n");
fputs($SMTP, "Subject: $Subject\n\n");
fputs($SMTP, "$Body\r\n.\r\n");
fputs($SMTP, "QUIT\n");
$InputBuffer = fgets($SMTP, 1024);

fclose($SMTP);
}

I believe I've modified the script sufficiently that it doesn't include anything specific to my configuration.. I apologize if I haven't. You'll need to replace "smtp.sitename.com" and "sitename.com" with your server's information.

jgalba

1:38 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Thank you I'll certainly give it a try. I have a couple of questions though.

Do you have to comment out or change the PHP.ini file settings?

Is this script secure?

What is the recommended smtp server to use? My ISP?

NickCoons

4:25 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



<Do you have to comment out or change the PHP.ini file settings?>

No.. you don't have to worry about the existing mail() function being there, or have to change anything else. But you do have to make sure that PHP was compiled with sockets.

<Is this script secure?>

I'm not sure what you mean. SMTP by nature is unsecure as everything is done in plain text.

<What is the recommended smtp server to use? My ISP?>

That would depend on your setup. If you are allowed to use the MTA on the box where the script runs, this would be fastest.

jgalba

8:15 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



One last question. How do I know if PHP was compiled with sockets?

Thank you by the way for your help.

NickCoons

12:38 am on Aug 6, 2004 (gmt 0)

10+ Year Member



If it hasn't been, then the function will complain that it cannot open the connection.. it'll appear as if the function that it's using to try and connect doesn't exist.

So basically, if it hasn't been compiled in, then it won't work :-).