Cep Posted November 1, 2006 Share Posted November 1, 2006 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 <[email protected]>'."\r\n"; break; case "DS": // DS = Design $headers .= 'From: Design <[email protected]>'."\r\n"; break; case "MSC": // MSC = Marketing Support to Client $headers .= 'Bcc: Marketing Support <[email protected]>'."\r\n"; $headers .= 'From: Marketing Support <[email protected]>'."\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 [email protected]#[email protected]#[email protected] 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 https://forums.phpfreaks.com/topic/25793-problem-with-a-new-mailer-script/ Share on other sites More sharing options...
dagnasty Posted November 1, 2006 Share Posted November 1, 2006 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 protected]"; $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 https://forums.phpfreaks.com/topic/25793-problem-with-a-new-mailer-script/#findComment-117794 Share on other sites More sharing options...
Cep Posted November 2, 2006 Author Share Posted November 2, 2006 Doesn't appear to make a difference even if I add $to = trim($emails[$x]); I am still being told the address is invalid. Link to comment https://forums.phpfreaks.com/topic/25793-problem-with-a-new-mailer-script/#findComment-118374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.