Forum Moderators: coopster

Message Too Old, No Replies

php mail script problem

         

andrewsmd

10:58 pm on Feb 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use the built in mail functions twice in one page to send two emails. I am having issues because most of the time it works but every once and a while it errors. Could this issue because I call two mail functions back to back? I can't get any detailed error because this is an existing system and the client doesn't want to pay for me to re design this using the smtp mail function. I have checked the error logs on the server and there is nothing in there at a time when the email errors. Does anyone have any idea of how I can trouble shoot this or thoughts on why this errors only sometimes? Here is the code it's very simple

// send email to proferrin
mail($adminto, $adminSub, $adminText, $adminHead);
// if (mail($adminto, $adminSub, $adminText, $adminHead)) throw new Exception('admiin receipt failed');

// send email to customer
mail($billingto, $billingSubject, $billingText, $billingHeaders);
// if (mail($billingto, $billingSubject, $billingText, $billingHeaders)) throw new Exception('customer receipt failed');

chadhaajay

7:32 am on Feb 18, 2010 (gmt 0)

10+ Year Member



What kind of a customer he is if he doesn't want to pay for problem solution? Tell him that nothing comes for free my friend!

Matthew1980

8:08 am on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Andrewsmd,

Calling the mail function back to back is fine, I do it myself In a couple of scripts I have done, primarily because I can't be bothered to install the phpmailer, and its less code ;-p So long as the message is structured correctly, and the headers are included you shouldn't really have an issue, though, the only drawback with mail is you cannot guarantee that the mail has been sent, and to be honest I have noticed quite long delays once the message is sent, 1 particular instance took almost 2 hours - but it got there. Aparently, the mail function doesnt return any bool either, so it is just a shot in the dark...

This is how i typically structure a mail function:-

$mailheaders = "MIME-version: 1.0\r\n";
$mailheaders .= "content-type: text/plain; charset=UTF-8\r\n";
$mailheaders .= "From: you <you@yoursite.com>\r\n";

$subject_mail = "Message subject";
$email = "enquire@thisdomain.com";
$contents = "Hello this is a test message, hopefully you wil get it";
mail($email, $subject_mail, $contents, $mailheaders);


That works fine for me! If I need dual emails, i pop them in a function, then call them back to back.

chadhaajay: I couldn't agree more!

Cheers,

MRb

franco190453

2:12 pm on Feb 18, 2010 (gmt 0)

10+ Year Member



Andrewsmd:

The mail function only deliver the mail to a mail server;
and the server only checks a group of things like,
if it contains a destination mail, a subject, a message and the
proper headers plus other simple things.
The mail server deals with the destination server and
technically is like a new world that is known only to the
mail server, things like delay or Rejection are only known
to the mail server.

Hope it helps
Regards
Franco

andrewsmd

2:36 pm on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chadhaajay, I don't know if you work in the industry, but most customers seem to have this sense of free entitlement to fixes once you build them a website. It may be 10 years old but they think it should just work indefinitely. I tell them that if you buy a car and have to change the tires, you don't just go back to the car dealer and expect them to give you free new tires.

I think I found the problem. It had nothing to do with the code. It was with our mail system not having the user listed since we host their mail.

rocknbil

6:23 pm on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Off topic a little, but

most customers seem to have this sense of free entitlement to fixes once you build them a website.


The have this sense of entitlement only because we let them. And the usual reason for letting them load free updates on us is from our own egos, we're too afraid if we don't "work for free" we will lose the project. Put it in terms they understand: your time is important, right? So is mine. Enough of these cross your desk and you realize you don't need this kind of work (read: irritation.)

At any rate, the usual way this is handled,

if (mail($adminto, $adminSub, $adminText, $adminHead)) {
// continue with success message
}
else {
// log the incident here, everything you can, display error message
}