Jump to content

Problem with a new mailer script


Cep

Recommended Posts

Hello I am working on a new mailer for part of a system I am developing and I am running into a problem with the to address.

As far as I can tell there is nothing wrong with the code but the SMTP server continually responds that the email address being sent to it is invalid, I cannot see why as the addresses being used are valid.

Here is my function,

[code=php:0]
//************************************** sysmailer function ******************************************//
function sysmailer($recipients, $mainbody, $subject, $sender) {
       
        // Count occurences of special seperator
        $count_addr = substr_count($recipients, "#");

        // If occurences are greater or equal to 1 then we need to explode the string to get each address
        if ($count_addr>=1) {
            $emails = explode("#", $recipients);
            $count = $count_addr + 1;
        } else {
            $emails = array();
            $emails[0] = $recipients;
            $count = 1;
        }

        $message = "<html>
                    <head>
                    <title>Mail</title>
                    <style type='text/css'>
                    <!--
                    body, table {
                    font-family: Verdana, Arial, Helvetica, sans-serif;
                    font-size: 10pt
                    }

                    .str {
                    font-weight: bold;
                    }

                    .sml {
                    font-size: 8pt;
                    }

                    .lrg {
                    font-size: 12pt;
                    }

                    .red {
                    color: red;
                    }

                    .white {
                    color: #FFFFFF;
                    }
                    // -->
                    </style>
                    </head>
                    <body>
                    {$mainbody}
                    </body>
                    </html>";

        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0'."\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";

        for ($i = 1; $i <= $count; $i++) {

            $x = $i - 1;

            $to = $emails[$x];

            //Additional Headers
            $headers .= 'To: '.$to.'<'.$to.'>'."\r\n";

            switch ($sender) {
                    case "MS":
                        // MS = Marketing Support
                        $headers .= 'From: Marketing Support <marketing.support@myaddress.com>'."\r\n";
                        break;
                    case "DS":
                        // DS = Design
                        $headers .= 'From: Design <design@myaddress.com>'."\r\n";
                        break;
                    case "MSC":
                        // MSC = Marketing Support to Client
                        $headers .= 'Bcc: Marketing Support <marketing.support@myaddress.com>'."\r\n";
                        $headers .= 'From: Marketing Support <marketing.support@myaddress.com>'."\r\n";
                        break;
            }
            // Mail it
            mail($to, $subject, $message, $headers) or die("Error sending mail:<br /><br />To: $to<br /><br /> Subject: $subject<br /><br />Message Body: $message<br /><br />Headers: $headers<br /><br />");
        }

$mailarray = array ($count,"Mails required: {$count}, Mails sent: {$x}");

return $mailarray;
}[/code]

The arguement $recipients can be a string of multiple email addresses seperated by a # sign. for example you@you.com#me@me.org#them@them.net or it can be a single email address. The function then works out the number of addresses and then should loop through and send these to the mail function.

I cannot see a problem with the code itself and when the warning message returns the problem I can see that the variable $to is being assigned a proper address. So whats the problem do you think?
Link to comment
Share on other sites

I don't really want to look through it, but if you want you can use my old script as a reference.

[code=php:0]
<?
if (isset($contactsubmit))
{
$myemail = "email@email.com";

   

     
$i = 0;

if(!$visitormail == "" && (!strstr($visitormail, '@') || !strstr($visitormail, '.')))
{
$invalidemail = 1;
$i += 1;
}
if (empty($visitor))
{
$invalidvisitor = 1;
$i++;
}
if (empty($notes))
{
$invalidnotes = 1;
$i++;
}
if ($i == 0)
{
$todayis = date("l, F j, Y, g:i a") ;


$subject = "Contact";

$notes = stripcslashes($notes);

$ipi = getenv("REMOTE_ADDR");
$httpagenti = getenv("HTTP_USER_AGENT");

$message = "$todayis [EST] \n Message: $notes \n From: $visitor ($visitormail)\n Additional Info : IP = $ipi \n Browser Info: $httpagenti \n";

$from = "From: $visitormail\r\n";
mail($myemail, stripcslashes($subject), $message, $from);
echo "Message sent. Thanks!";
$ismailed = 1;

} else { echo "Error. Check below"; }
}
?>
<?
if (empty($i) || $i != 0)
{
if (!isset($ismailed))
{

?>


        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

         
            <?php if ($invalidvisitor == 1){ echo "<font color=red>"; } ?>
            Name:
            <?php if ($invalidvisitor == 1){ echo "</font>"; } ?>
            <input type="text" name="visitor" size="35" />
            <?php if ($invalidemail == 1){ echo "<font color=red>"; } ?>
            <br>
            Email:
            <?php if ($invalidemail == 1){ echo "</font>"; } ?>
            <input type="text" name="visitormail" size="35" value="<?php echo $visitormail; ?>" />
            <?php if ($invalidnotes == 1){ echo "<font color=red>"; } ?>
            <br>
            <br>
Message:<br>
            <?php if ($invalidnotes == 1){ echo "</font>"; } ?>
            <textarea name="notes" rows="4" cols="40"></textarea>
            <br />
            <input type="submit" value="Send" name="contactsubmit" />
         
        </form>
<?}
} ?>
[/code]
Link to comment
Share on other sites

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.