Jump to content

Recommended Posts

Hi

 

I have a form which sends out an email. I'm trying to send it to muliple people.

The following is my code:

 

        $to  = "bob@example.com"; 

    $subject = "New Applicants submit";

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    /* headers adicionais */
    $headers .= "To: Jim <jim@example.com>, Ted <ted@example.com>\r\n";
    $headers .= "From: Web <website@example.com>\r\n";

    mail($to, $subject, $msg, $headers);

 

This all works fine when I put the email addresses of some of my colleagues (using Gmail). But If I try putting any other email, those who use Outlook, no-one receives the emails.

 

Is there anything wrong with my form?

Link to comment
https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/
Share on other sites

You need to add the additional recipients to the $to section adding them to the headers is not enough that just notifies the others as to who the email was sent. Also if it works on a gmail account then it is fine, sounds like you have the wrong emails or the outlook users do not have there email client setup right, or it is filtering it as spam, be sure to check junk folder in outlook.

$to  = "bob@example.com, ted@example.com, jim@example.com";

 

Will this do?

 

Yes. :)

 

Their has been a post before who had problems sending his mail to multiple recipients using $to. Altough 'to' can accept multiple recipients it's probably better - for spam sake's - to only add 1 'to' recipient and split all others over cc and bcc

$to  = "bob@example.com, ted@example.com, jim@example.com";

 

Will this do?

 

Yes. :)

 

Their has been a post before who had problems sending his mail to multiple recipients using $to. Altough 'to' can accept multiple recipients it's probably better - for spam sake's - to only add 1 'to' recipient and split all others over cc and bcc

 

That's interesting! Definitely keeping that in mind. (Usually, in the far few in between cases where I use mail(), I just hold a while() statement and send each person an individual email).

So something along the lines of:

 

        $to  = "bob@example.com";

    $subject = "New Applicants submit";

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    /* headers adicionais */
    $headers .= "From: Web <website@example.com>\r\n";
    $headers . = "Cc: jim <jim@example.com>, ted <ted@example.com>";

    mail($to, $subject, $msg, $headers);

My code is :

 

    $to  = 'jim@example.com, bob@example.com, ted@example.com';

    $subject = "New Applicants submit";

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    $headers .= "To: Ted <ted@example.com>, bob <bob@example.com>, jim <jim@example.com>\r\n";
    $headers .= "From:  Website <website@example.com>\r\n";

        $to = explode(',',$to);
        foreach($to as $recipient)
        {
        mail($recipient,$subject,$msg,$headers);
        }

 

Should this work?

Ok I have the following code now, and only I can get the emails:

 

            $to  = 'client1@example.co.uk,client2@example.co.uk,me@example.com';

                $subject = "Form Submit";

                $headers  = "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

               $headers .= "To: Client1 <client1@example.co.uk>,Client2 <client2@example.co.uk>,Me <me@example.com>\r\n";
               $headers .= "From: Website <website@example.co.uk>\r\n";

               $to = explode(',',$to);
               foreach($to as $recipient)
               {

                if (mail($recipient, $subject, $message, $headers))
                {
                    header('Location: thankyou.php');
                }
                else
                {
                   echo("<p>Message delivery failed...</p>");
                }
            }

 

I get the emails fine. But the other 2 email addresses don not receive anything.

 

Is there anything wrong with my code?

 

Thanks

Ok I have the following code now, and only I can get the emails:

 

            $to  = 'client1@example.co.uk,client2@example.co.uk,me@example.com';

                $subject = "Form Submit";

                $headers  = "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

               $headers .= "To: Client1 <client1@example.co.uk>,Client2 <client2@example.co.uk>,Me <me@example.com>\r\n";
               $headers .= "From: Website <website@example.co.uk>\r\n";

               $to = explode(',',$to);
               foreach($to as $recipient)
               {

                if (mail($recipient, $subject, $message, $headers))
                {
                    header('Location: thankyou.php');
                }
                else
                {
                   echo("<p>Message delivery failed...</p>");
                }
            }

 

I get the emails fine. But the other 2 email addresses don not receive anything.

 

Is there anything wrong with my code?

 

Thanks

 

There is nothing wrong with your code. It's probably the SPAM filters that stop your e-mail from being received either send each e-mail individually or only add one $to and add the others to $cc or $bcc

Ok I now have this:

 

     $to = 'me@example.com';
                $subject = "Form Submit";

               $headers .= "From: Website <me@example.com>\r\n";
               $headers .= "To: me2@example.com\r\n";
               $headers .= "Cc: clients1@example.co.uk\r\n"; 
               $headers .= "Bcc: client2@example.com\r\n";
                $headers .= "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

                if (mail($to, $subject, $message, $headers))
                {
                    header('Location: thankyou.php');
                }
                else
                {
                   echo("<p>Message delivery failed...</p>");
                }

 

Does this look ok?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.