Jump to content

PHP Form - not receiving email


Gainax

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  = "[email protected]"; 

    $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 <[email protected]>, Ted <[email protected]>\r\n";
    $headers .= "From: Web <[email protected]>\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.

 

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

 

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  = "[email protected]";

    $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 <[email protected]>\r\n";
    $headers . = "Cc: jim <[email protected]>, ted <[email protected]>";

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

My code is :

 

    $to  = '[email protected], [email protected], [email protected]';

    $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 <[email protected]>, bob <[email protected]>, jim <[email protected]>\r\n";
    $headers .= "From:  Website <[email protected]>\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  = '[email protected],[email protected],[email protected]';

                $subject = "Form Submit";

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

               $headers .= "To: Client1 <[email protected]>,Client2 <[email protected]>,Me <[email protected]>\r\n";
               $headers .= "From: Website <[email protected]>\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  = '[email protected],[email protected],[email protected]';

                $subject = "Form Submit";

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

               $headers .= "To: Client1 <[email protected]>,Client2 <[email protected]>,Me <[email protected]>\r\n";
               $headers .= "From: Website <[email protected]>\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 = '[email protected]';
                $subject = "Form Submit";

               $headers .= "From: Website <[email protected]>\r\n";
               $headers .= "To: [email protected]\r\n";
               $headers .= "Cc: [email protected]\r\n"; 
               $headers .= "Bcc: [email protected]\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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.