mfoster Posted January 20, 2009 Share Posted January 20, 2009 I have a whole bunch of php scripts that utilize the mail() function. They have worked fine previously, but now, although they work, are very slow (20-30 seconds). I have written a couple of testing programs to make sure that the slow completion was due to the mail() function and have shown it is definitely related to it. In one program, I send the mail and in the other program I put comment code (//) in front of the mail statement so that everything else in the program is identical. The program with the active mail runs 20-30 seconds, while the inactivated mail program runs in less than 2 or 3 seconds. I have not changed the code in the scripts, but the hosting company did move to a new server. The technician for the hosting site tells me that it is NOT a server problem, but a php coding problem. I honestly don't see how that could be true, but an open to any suggestions that anyone else has. Here is the code (with the mail function disabled) that seems to be the problem: $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; // now lets send the email. //mail($to, $subject, $message, $headers); I would be most appreciative of any suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/ Share on other sites More sharing options...
DeanWhitehouse Posted January 20, 2009 Share Posted January 20, 2009 It might be something wrong with your headers on the code, or could be because of the email address you are sending to (or if you are sending multiple emails) Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-741466 Share on other sites More sharing options...
mfoster Posted January 20, 2009 Author Share Posted January 20, 2009 It doesn't seem to matter whether I send it to one person, or three. Here's what I have for the header: $to = "mfoster@xxxxxx.org"; $from = "Conference Registration System"; $subject = "Conference Request Update - Notification of approval"; $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; It seems to follow the rules, but please point out problems if you see them Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-741564 Share on other sites More sharing options...
DeanWhitehouse Posted January 20, 2009 Share Posted January 20, 2009 Your missing a mime type, try looking at the manual on how to use the mail feature to send html emails http://uk2.php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-741568 Share on other sites More sharing options...
mfoster Posted January 20, 2009 Author Share Posted January 20, 2009 Well, I looked up the reference that you cited and editted my code to the following: $from = "Conference Registration System"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: html; charset=iso-8859-1' . "\r\n"; $headers = "From:" . $from . "\r\n"; // now lets send the email. mail($to, $subject, $message, $headers); Unfortunately, it had no effect on the time it takes for the script to work. However, now the email comes out with the source code for the html message rather than the display of the code! Not good. Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-741608 Share on other sites More sharing options...
DeanWhitehouse Posted January 21, 2009 Share Posted January 21, 2009 Hmm, have you tried contacting your host about this or is it localhost? Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-742426 Share on other sites More sharing options...
mfoster Posted January 22, 2009 Author Share Posted January 22, 2009 The host maintains that all of their equipment are working properly and that it is a problem with php coding which they do not support. I resubmitted the trouble ticket and replied that it certainly looks like it's a server problem and NOT a php problem. So far no new replies. Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-742796 Share on other sites More sharing options...
scottjcampbell Posted January 22, 2009 Share Posted January 22, 2009 Some mail servers purposely make mail slow when sent via web scripts to help reduce spam Quote Link to comment https://forums.phpfreaks.com/topic/141651-slow-mail-function/#findComment-742814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.