Jump to content

function send() - problem with access mail

- - - - -

  • Please log in to reply
6 replies to this topic

#1
AdrianWierciochPHP

AdrianWierciochPHP

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
Hi!

I try send e-mails to my base which look like this:


wiercioch.adrian1993@gmail.com

wiercioch.adrian@gmail.com

wierciochadrian93@gmail.com


by this code (mails are in $mails array)

for ($i = 0;$i <= count($mails); $i++)

{

     mail($mails[$i], $subject, $message);

}


And it`s sending for one of this mails - the last one. Can I tell me how change it or how will I write simply good code to send it?
I need your help so much

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Try this maybe (replacing the address after -f with the host you are sending from, such as no-reply@example.com):
foreach($mails as $mail)
{ 
     mail($mail, $subject, $message, null, "-fpostmaster@example.com"); 
}  
You were also overrunning the array, it should be '<' not '<='
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
AdrianWierciochPHP

AdrianWierciochPHP

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
I have searched some mail-systems (e.g. PHPMailer) but this systems require log in to smtp or pop3 and I have to use systems sending something like spam - by only mail() function. I know it exists but I can not search anything and I want have own system but first I need help with code above. If you can, please help me write some class to send or at least improve my code.

#4
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
I think that maybe you need to check your $message and $subject variables.
probably try to look what script says. There is nothing wrong in code you posted,except <= thing.
but you may consider refactor it to sends a one mail only. Mail() can take several mails at once.
for e.g. mail(implode(', ',$mails),$subject,$message);
And also
from php.net "When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini."
so you can write this

$headers = 'From: webmaster@example.com' . "\r\n" .

    'Reply-To: webmaster@example.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

 mail(implode(', ',$mails),$subject,$message,$headers);


Hope this will help.

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200

ghost_x47 said:

Mail() can take several mails at once.
If I recall the MTA will expose all the emails in the to: header, at the client.

Adrian said:

I have searched some mail-systems (e.g. PHPMailer) but this systems require log in to smtp or pop3 and I have to use systems sending something like spam

Your system's sendmail command will need to connect to an smtp server regardless, the host 's MTA is set up to connect to it. You can create a config file, and ask the user to place the SMTP server, username and password to connect to if, if you want to use PHPMailer.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts

Alexander said:

If I recall the MTA will expose all the emails in the to: header, at the client.
You right, i doesn't think about it, i just think about efficient way to send lesser amount of mails. Since than i think foreach loop will be good and maybe sleep )

Alexander said:

Your system's sendmail command will need to connect to an smtp server regardless, the host 's MTA is set up to connect to it. You can create a config file, and ask the user to place the SMTP server, username and password to connect to if, if you want to use PHPMailer.
As i know, PHPmailer can use Smtp or sendmail or mail functions, isn't it?

#7
AdrianWierciochPHP

AdrianWierciochPHP

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
yes it is. PHPMailer provide function like isMail() to set sending method (are also SMTP and POP). I use additional headers but I do not use it in this post. I use foreach loop because I want handle not sent mails to $notSent array. I will try PHPMailer for several days when I will be home (now I`m away) and I will post hear my application send mails.
If not I will have to use SMTP :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users