1

I have PEAR Mail and Mail_mime all working very nicely using gmail's SMTP server to send. Thanks to some posts on here that helped me get that far!

But, in some scenarios, I need to send two emails, with different content, and to different recipients one right after the other. This is refusing to work.

I can confirm both the emails I am trying to send are well-formed and valid, as both will send with the other one commented out. But whenever I attempt to send them both, only the first gets through. I have tried putting php to sleep for 10 seconds in between, and I have tried sending the second email in a different script that gets called after the end of the first. Nothing.

I realise this is a pretty obscure problem as I found no other articles mentioning this. I haven't included any code because, as stated, I know the code works fine.

So I am hoping in vein that someone might have a bright idea as to why this might be.

Thanks in advance.

Hatcham
  • 330
  • 3
  • 10
  • Are you SURE the code works fine? Could it be something simple, like you have a variable that contains data from both messages and so invalid content is sent second time around? – SimonMayer Feb 06 '12 at 19:33
  • I am sending the mail using a function. I call this function, with email address, subject and body as paramater, each time I want to send a mail. I have now set up a test page where I call the function twice, with the same content etc, just different email addresses - again only the first gets through. Thei si nowt to do with gmail I have also discovered, as I am now using ta different SMTP server, which displays the same behaviour. So I suspect, perhaps, I need to close or disconnet the smpt connection, or something? – Hatcham Feb 07 '12 at 09:44
  • additional info: i can more than one email within a single call to a function (looping through an array of recipients, within the function). this does not solve my problem of not being able to call my function twice, which is neccesary as I often need to send two entirely different emails within a single script. – Hatcham Feb 07 '12 at 10:19
  • 1
    SOLVED: changing include('Mail.php'); to require_once('Mail.php'); fixed the problem. – Hatcham Feb 07 '12 at 10:37
  • Please can you add that as an answer, to make it clear for future readers of this question? – SimonMayer Feb 07 '12 at 11:08

1 Answers1

0

SOLVED: changing

include('Mail.php'); 

to

require_once('Mail.php'); 

fixed the problem.

Hatcham
  • 330
  • 3
  • 10