FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Mail() Help





moejoe
Hey Guys,

I'm Trying to Generate a Script That can Send Multiple E-Mails in one easy form.

Heres my Current Script:
Code:

   $name = $_POST['name'];
   $email = $_POST['email'];

  if(is_array($resultarray))
   {
                    //Gets Addressbook
      $names = array_shift($resultarray);
      $emails = array_shift($resultarray);
      
      $max = count($names);

      for ($i=0; $i<$max; $i=$i+1)
      {
       
        mail($emails[$i],"$names[$i] Has Sent You...","$body");
}



This Works, However it apears as spam (no sender).

I wanted the code to work like this:
Code:

   $name = $_POST['name'];
   $email = $_POST['email'];

  if(is_array($resultarray))
   {
                    //Gets Addressbook
      $names = array_shift($resultarray);
      $emails = array_shift($resultarray);
      
      $max = count($names);

      for ($i=0; $i<$max; $i=$i+1)
      {
       
        mail($emails[$i],"$names[$i] Has Sent You...",$body,"From: $email\n);
}


This Script works.
So, Im thinking that the Headers Need some work...But What?
But it only sends about 3 emails out of the tested 203.
:S

Thanks For All Your Help.
jeremyyak
I haven't worked much with mail(), but my suggestion would be to make a delay between sending each email. A mail server can only take so much at once Razz
~Jeremy~
moejoe
True,

But Without the Headers, The Server Returns more then 3/4 of the Emails.
Aredon
A function I wrote for doing it:
Code:

<?php
function dispatchEmail($to,$from,$subject,$message){
   $headers = 'From: '.$this->from."\r\n".
     'Reply-To: '.$this->from."\r\n" .
     'X-Mailer: PHP/' . phpversion();
   return mail($to,$subject,$message,$headers);
}
?><?php
if(dispatchEmail($_POST['email'],'me@mysite.com','hi','hi')){
?>
Thank you for taking the time to fill out the form!  An email has been dispatched to <?= $_POST['email']; ?>
<? }else{ ?>
Error: Could not send email to <?= $_POST['email']; ?>
<? } ?>


And a class I wrote once that does the trick too which requires more lines of code in your page's body however is much more clear to WHOM it's from and sending to and which is the subject and which is the message:
Code:

<?php
class Email{
   var $to,$from,$subject,$message;
   function dispatch(){
   $headers = 'From: '.$this->from."\r\n".
     'Reply-To: '.$this->from."\r\n" .
     'X-Mailer: PHP/' . phpversion();
   return mail($this->to,$this->subject,$this->message,$headers);
   }
}
?><?php
$email=new Email;
$email->to=$_POST['email'];
$email->from='me@mysite.com';
$email->subject='hi';
$email->message='hi';
if($email->dispatch()){
?>
Thank you for taking the time to fill out the form!  An email has been dispatched to <?= $_POST['email']; ?>
<? }else{ ?>
Error: Could not send email to <?= $_POST['email']; ?>
<? } ?>



Side Note:
Might want to split the string $_POST['email'] for commas because they could trick you into more than one email addresses.
moejoe
Thanks For the Submission.

The Script Says from Whom the Email is from.

However, it only sends an email to one out of the 203 Recovered MSN contacts.

Yes, This is a MSN contact retriever and email-er.

The retrieving works.
But I'm unsure how to split the '$emails[$i]' so that all the retrieved receive an email. This $string has no commas in it.

Anyone got a Contact Retriever/Email-er Tutorial or Demo?

It would really Help..

Thanks Again!
moejoe
Hey, Got iT working.

However; This script only seems to work to my ISP email, and not to my Hotmail Email.

Which is bad, because when i retreieve msn emails; they are all Hotmail accounts. So none of them work :S.

Is there anyway to add extra headers to make the email send to Hotmail accounts?

Cheers.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.