Jump to content

mail function using too musch time to deliever mail


techrahul87

Recommended Posts

hello everyone,

 

                      i had used mail function in php. i was sending mail from my local host but in that case some errors were generated.

                      then i tried it from server. now mail function is working properly but it is taking about 2 or 3 horus to to reach the inbox.

 

                      is this a normal time.

:confused:

Link to comment
Share on other sites

Well from your localhost you would need to have a mailserver configured for PHP to work with, hence the likely error you we're getting. As for putting it on an actual hosting account well that time really sucks. Email should be virtually instantanious maybe at worst occasionally a 15 minute delay depending on your hosting providers load. But also depending on your host provider and which email system your sending it to from there.. ie aol.com aim.com gmail hotmail other.. Some host providers like godaddy for example I dont know what they do behind the scenes after you send an email via a script but it seems to trickle down some kind of queue where after a little time you get it. But same notion applies to email providers sometimes emails get hung in there inbound system for a bit and take a little while to trickle down to your inbox. All in all 3 hours is a bit beyond what should be expected in any result.. and just to note

 

mail() doesn't control the speed of the send it only invokes an email to be sent with the parameters you provide through what ever email server its configured to.

Link to comment
Share on other sites

On another note. What are you sending out as a message. You could be causing flags to be thrown up that are hindering it's send process. Maybe an incorrect header? To many links? something else?

 

<?php 
function myDomainName()
{
	$mydomain = $_SERVER['HTTP_HOST'];
	$mydomain = str_replace('www.', '', $mydomain);
	return $mydomain;
}

function mailSomeone($toWho, $fromWho, $sysSubj, $sysMsg)
{
	$msgTemplate = '
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	<title>'.$sysSubj.'</title>
	</head>
	<style type="text/css">
		body{background: #EDEBEA;}
		#wrapper{background:#FFF;border:4px solid #DDD;width:650px;}
	</style>
	</head>
	<body>
	<div id="wrapper">'.$sysMsg.'</div>
	</body>
	</html>
	';
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	$headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n";
	$headers .= 'From:' .$fromWho. "\r\n";
	$headers .= 'Reply-To: ' .$fromWho. "\r\n";
	$headers .= '1\r\nX-MSMail-Priority: High' . "\r\n";
	$headers .= 'X-Mailer: MonkeyTooth Productions Mail Controller v2.0' . "\r\n";
	mail($toWho, $sysSubj, $sysMsg, $headers);
}

//example
$sysSubj = '[Chris Hacia] Demo Email';
$sysMsg = '<img src="http://chrishacia.com/static/img/logo.png" border="0" alt="Christopher Hacia" /><br /><br />There is really nothing special about this email other than to demonstrate the HTML side of php\'s mail() function';

mailSomeone($_POST['theEmail'], 'no-reply@'.myDomainName(), $sysSubj, $sysMsg);
?>

 

Above is a nifty litte function I use time and time again that I made myself some time ago for sending email that can output as HTML and not just plaintext like the mail() function will do stand alone.

 

give it a whirl see it in action: http://chrishacia.com/demo/php-mail-html.php

Link to comment
Share on other sites

actually i m just 1 week experienced in php .

i was asked for a php page which sends mail for 5 html pages.

so i picked a code from internet and try to implement that page by sending hidden fields from all html pages...

//to get values from enquiry.html to send mail
if(!empty($_POST["enquiryhidden"]))
{
	$site_admin=$_POST["mailto"];   // to whom mail has to be sent
	$name=$_POST["name"];           // name from user
	$Email=$_POST["email"]; 		// email of user
	$phone=$_POST["telephone"];		//user entries
	$mobile=$_POST["mobile"];       //user entries
	$address=$_POST["address"];		//user entries
	//$sub=$_POST["subject"];
	$sub="enquiry from:".$name."through http://www.jaibharatsteel.com";  //subject of the mail
	$mes=$_POST["comment"]; 		//message 
	$from = $name.' <'.$Email.'>';   
	$project=$_POST["project"];      //user entry
	//$data="mobile no: ".$mobile."\n"."phone no: ".$phone ."\n"."Address :".$address."\n"."Project :".$project."\n"."\n".$mes;  // message body
	$data="dear sir/mam"."\n"."\t".
	"you have new enquiry through your website."."\n"."\n".
	"\t".$mes."\n"."information of sender"."\n"."\n".
	"mobile no: ".$mobile."\n".
	"phone no: ".$phone ."\n".
	"Address :".$address."\n".
	"Project :".$project;
	ae_send_mail($from, $site_admin, $sub, $data,  // function calling
        array('X-Mailer'=>'PHP script at '.$_SERVER['HTTP_HOST']));
	}

//to get values from contactus.html to send mail
if(!empty($_POST["contacthidden"]))
{
	$site_admin=$_POST["mailto"];
	$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
	$name=$_POST["contact"];
	$Email=$_POST["email"];
	$phone=$_POST["telephone"];
	$mobile=$_POST["mobile"];
	$address=$_POST["address"];
	//$sub=$_POST["subject"];
	$sub="contact from: ".$name."through http://www.jaibharatsteel.com";
	$mes=$_POST["comment"]; 
	$from = $name.' <'.$Email.'>';
	//$data="mobile no: ".$mobile."\n".
	//"phone no: ".$phone."\n" 
	//."Address :".$address."\n"
	//.$mes;
	$data= "dear sir/mam"."\n"."\n"."\t"
       "you have queries comments and reqirments from your web site"."\n"."\t".$mes."\n"
   "the basic information of sender is shown as:"."\n".
   "phone no:".$phone."\n"
   ."Address :".$address."\n";
	ae_send_mail($from, $site_admin, $sub, $data,  // function calling
        array('X-Mailer'=>'PHP script at '.$_SERVER['HTTP_HOST']));
}




function ae_send_mail($from, $to, $subject, $text, $headers="")
{
    if (strtolower(substr(PHP_OS, 0, 3)) === 'win')
        $mail_sep = "\r\n";
    else
        $mail_sep = "\n";

    function _rsc($s)
    {
        $s = str_replace("\n", '', $s);
        $s = str_replace("\r", '', $s);
        return $s;
    }

    $h = '';
    if (is_array($headers))
    {
        foreach($headers as $k=>$v)
            $h = _rsc($k).': '._rsc($v).$mail_sep;
        if ($h != '') {
            $h = substr($h, 0, strlen($h) - strlen($mail_sep));
            $h = $mail_sep.$h;
        }
    }

    $from = _rsc($from);
    $to = _rsc($to);
    $subject = _rsc($subject);
    $val= mail($to, $subject, $text, 'From: '.$from.$h);
if($val)
{
	echo "your mail has been sent";
}
else
{
	echo "oops! try again";
}
}	 

 

now i dont have much idea about that user defined function ( ae_send_mail) i just got it from the internet.....there was written that it will improve secuirity....code is working fine for both pages.....but i m not sure of this code.

comments please................... :'(

Link to comment
Share on other sites

I am not familiar with what ever code it is you have there. At a quick glance it looks like a jarbled mess. I'd personally suggest my bit of code and see how that may help ya.

 

I did a quick check on X-Mailer however. Which your code looks like it may derive from. Found this interesting article (though didnt read through it all). This could be in part why your mail is sending so slow.

 

http://www.mailingcheck.com/faking-x-mailer-email-field-never-rewards/

 

Also might I suggest not sending an email per page load to someone. Thats likely to piss off your hosting provider real quick, may also invoke hourly limits your provider has to trigger stopping mail from sending as well. Example I host most of my sites on Host Gator. They will only let me send 500 emails per hour collectively from site or email account. And chances are you have limits like that unless your on a really good VPS or Dedicated box.

 

That said if you want to log what page is being landed on and when, maybe using a database is in your best interest. Where you can then run a script daily to give you a digest of the days, weeks, months activities.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.