nsForum logo

Welcome Guest ( Log In )

 
Reply to this topicStart new topic
> Php Mail() Sending Very Slow
Ferguson
post Aug 24 2015, 01:03 PM
Post #1





Group: Verified NS Member
Posts: 1
Joined: 24-August 15
Member No.: 24,355



I have a php mail() form on a webpage that sends an email and an attachment when the user selects submit. The issue is the email DOES eventually send however it can take 10 to 15 minutes or even longer. In addition, when they do come through I seem to get any emails sent since the last time all at once.

I'll post the code below, but I'm not sure it is the code because I have several Wordpress plugin forms that send emails and they are also very delayed. I've also tried setting up very simple mail() commands to test the issue and again I get the same delay.

Any help would be greatly appreciated. Thank you.

CODE
$htmlbody = "Please find attached your document.";
        $to = email@email.com; //Recipient Email Address
        $subject = "Subject"; //Email Subject
        $headers = "From: test@email.com\r\nReply-To: test@email.com\r\n";
        $headers .= "CC: secondEmail@email.com";
        $random_hash = md5(date('r', time()));
        $headers .= "\r\nContent-Type: multipart/mixed;
        boundary=\"PHP-mixed-".$random_hash."\"";
        // Set your file path here
        $filename = "test.pdf";
        $pdfdoc = $html2pdf->Output('', 'S');
        $attachment = chunk_split(base64_encode($pdfdoc));
        
        
        //define the body of the message.
        $message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative;
        boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
        $message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain;
        charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
        
        
        //Insert the html message.
        $message .= $htmlbody;
        $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
        
        
        //include attachment
        $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip;
        name=\"$filename\"\r\n"."Content-Transfer-Encoding:
        base64\r\n"."Content-Disposition: attachment\r\n\r\n";
        
        $message .= $attachment;
        $message .= "/r/n--PHP-mixed-$random_hash--";
        
        
        //send the email
        $mail = mail( $to, $subject , $message, $headers );
Go to the top of the page
 
+Quote Post
Craig
post Aug 25 2015, 07:04 PM
Post #2





Group: Administrators
Posts: 988
Joined: 23-June 08
From: Pennsylvania
Member No.: 1,317



QUOTE (Ferguson @ Aug 24 2015, 02:03 PM) *
I have a php mail() form on a webpage that sends an email and an attachment when the user selects submit. The issue is the email DOES eventually send however it can take 10 to 15 minutes or even longer. In addition, when they do come through I seem to get any emails sent since the last time all at once.

I'll post the code below, but I'm not sure it is the code because I have several Wordpress plugin forms that send emails and they are also very delayed. I've also tried setting up very simple mail() commands to test the issue and again I get the same delay.

Any help would be greatly appreciated. Thank you.

CODE
$htmlbody = "Please find attached your document.";
        $to = email@email.com; //Recipient Email Address
        $subject = "Subject"; //Email Subject
        $headers = "From: test@email.com\r\nReply-To: test@email.com\r\n";
        $headers .= "CC: secondEmail@email.com";
        $random_hash = md5(date('r', time()));
        $headers .= "\r\nContent-Type: multipart/mixed;
        boundary=\"PHP-mixed-".$random_hash."\"";
        // Set your file path here
        $filename = "test.pdf";
        $pdfdoc = $html2pdf->Output('', 'S');
        $attachment = chunk_split(base64_encode($pdfdoc));
        
        
        //define the body of the message.
        $message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative;
        boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
        $message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain;
        charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
        
        
        //Insert the html message.
        $message .= $htmlbody;
        $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
        
        
        //include attachment
        $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip;
        name=\"$filename\"\r\n"."Content-Transfer-Encoding:
        base64\r\n"."Content-Disposition: attachment\r\n\r\n";
        
        $message .= $attachment;
        $message .= "/r/n--PHP-mixed-$random_hash--";
        
        
        //send the email
        $mail = mail( $to, $subject , $message, $headers );

Sorry about the sending delay, but as a shared system, it depends how many other packages are sending at the same time. In my experience, I have found that using the Pear Mail functin instead of the built-in PHP mail function or using SMTP (localhost for SMTP server on port 25 with no login or password) often send more quickly.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version    Network Solutions © 2011 Time is now: 30th March 2017 - 07:14 AM
Domain Names | Web Hosting | Web Design | Shopping Cart Software | Online Marketing | SSL Certificates