PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 15, 2018 12:32 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Oct 06, 2018 10:38 am 
Offline
Forum Commoner

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 33
Hi,

I was creating this little program to help me out sending emails but there is a issue i can't solve.

Convert a resource to a string
$file returns Resource id #3 instead of the value of the string

Here is a code example:
Code:
<?php
$file = fopen("emails.txt","r");

while(! feof($file))
  {
  mail($file, 'Thanks for joining!', Hi\nWe are glad to see you onboard\n\nPrivateloader);
  echo fgets($file). " - just received a email.<br>";
  }

fclose($file);
?>


Thanks


Top
 Profile  
 
PostPosted: Sun Oct 07, 2018 9:35 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13585
Location: New York, NY, US
The $file variable is a resource returned by fopen(). The first parameter for mail() should be a string containing the email address of the recipient.

Are the email addresses in the file? If so, then read the line into a variable:
Syntax: [ Download ] [ Hide ]
  $email = fgets($file);
  mail($email, 'Thanks for joining!', Hi\nWe are glad to see you onboard\n\nPrivateloader);
 

_________________
(#10850)


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 1:56 pm 
Offline
Forum Commoner

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 33
Thanks it really helped.

I have one other question how do i increase the time limitation of 30 seconds per execution in PHP?
I'm having problems running the whole script under 30 seconds.


Top
 Profile  
 
PostPosted: Sat Oct 13, 2018 7:14 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13585
Location: New York, NY, US
sjuaq wrote:
I have one other question how do i increase the time limitation of 30 seconds per execution in PHP?
I'm having problems running the whole script under 30 seconds.

You cannot really speed up how fast mail is sent. You probably need to call the script multiple times. Each call would only sends a small number of emails. But then, you will need to keep track of the number of the last email. It would be much easier with a database. Each record could have the email address and whether it had been send. Then just select the next N unsent email each call, and mark them in the database when they are sent.

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group