• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Problems with mail()

Hello,
I have a problem with this php page (that worked for 2 years on godaddy hosting....now I changed hosting  always within plan godaddy and it's no longer working!).
I receive the following error everytime I try to send a newsletter to a list of addresses, and I receive it for every mail() executed:
Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/m/a/x/maxone73/html/omissis/manager/spedisci_news.php on line 168  and I don't know which is the bad parameter...

Here is the code:

                    //   I get the content of the newsletter and the title
      $conn = mysql_connect("omissis", "omissis", "omissis");
      mysql_select_db("omissis",$conn);
      $sql = "SELECT * FROM contenuto";
      $result = mysql_query($sql, $conn) or die(mysql_error());
      while ($row = mysql_fetch_row($result))
                              {
                                    $id=$row[0];
                                    $titolo=$row[1];                                    $contenuto=$row[2];
                                               }
      // (5) Close the database connection
      mysql_close($conn);            

      
      // I load the list of email addresses
      $valori = $_POST['da_spedire'];
      $size = sizeof($valori) - 1;      
      $conn = mysql_connect("omissis", "omissis", "omissis");
      mysql_select_db("omissis",$conn);
      
      
      $k = 0;
      $i = 0;
                  
                  while ($k<=$size)
                        {                              
                        $sql = "SELECT id, mail, security FROM newsletter WHERE id=" . $valori[$k];
                                       $result = mysql_query($sql, $conn) or die(mysql_error());
                        while ($row = mysql_fetch_row($result))
                                    {                                                                              $mail[$i]=$row[1];
                              $security[$i]=$row[2];                                          
                                    }                  
                              $i++;      
                              $k++;
                        }      
      // (5) Close the database connection
      mysql_close($conn);            

      





      //HERE I SEND THE MAIL!!!!
      $size = sizeof($mail) - 1;      
      $k = 0;
      $headers = "From: ME MAX <info@omissis.com>\r\n $from\nContent-Type: text/html; charset=iso-8859-1";
                  while ($k<=$size)
                        {                                    

$testo_news='<style type="text/css">
<!--
a:link {
      color: #FFFFFF;
      text-decoration: none;
}
a:visited {
      text-decoration: none;
      color: #FFFFFF;
}
a:hover {
      text-decoration: underline;
      color: #FF9900;
}
a:active {
      text-decoration: none;
}
-->
</style>
<table width="100%" height="600"  border="0" align="center" cellpadding="4" cellspacing="0">
  <tr>
    <td valign="top" background="http://www.omissis.com/img/back_dark.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" background="http://www.omissis.com/img/back_dark.gif"><table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="left"><img src="http://www.omissis.com/img/logo.gif" width="438" height="75"></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
            <td>&nbsp;</td>
      </tr>
        <tr>
        <td colspan="2" style="color: white; font-size: 10px font-family: Arial, Helvetica, sans-serif;"><a href="http://www.omissis.com" target="_blank"><font color="#FFFFFF">www.omissis.com</font></a></td>
      </tr>
         <tr>
        <td>&nbsp;</td>
            <td>&nbsp;</td>
      </tr>
      <tr>
        <td rowspan="3" valign="top" width="100%"><table width="100%"  border="0" align="center" cellpadding="2" cellspacing="0">
          <tr>
            <td style="color: white; font-size: 14px font-family: Arial, Helvetica, sans-serif;">' . $titolo . '</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td style="color: white; font-size: 12px font-family: Arial, Helvetica, sans-serif;">' . nl2br($contenuto) . '</td>                  
          </tr>
        </table></td>
        <td width="152" height="120"><table width="152" height="115" border="0" align="right" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td><div align="center"><img src="http://www.omissis.com/img/foto/panorama_s.jpg" width="150" height="113"></div></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="120" width="152"><table width="152" height="115" border="0" align="right" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td><div align="center"><img src="http://www.omissis.com/img/interno_bar.jpg" width="150" height="113"></div></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="120" width="152"><table width="152" height="115" border="0" align="right" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td><div align="center"><img src="http://www.omissis.com/img/interno_saletta.jpg" width="150" height="113"></div></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="25">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td style="color: white; font-size: 12px font-family: Arial, Helvetica, sans-serif;">Vieni a trovarci sul nostro sito: <a href="http://www.omissis.com" target="_blank"><font color="#FFFFFF">http://www.omissis.com</font></a></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" style="color: white; font-size: 10px font-family: Arial, Helvetica, sans-serif;">Se non desideri ricevere la nostra newsletter <a href="http://www.omissis.com/canc_newsletter.php?posta=' . $mail[$k] . '&sec=' . $security[$k] .'&op=1" target="_blank"><font color="#FFFFFF"><strong>clicca qui</strong></font></a> e segui le indicazioni che troverai, oppure copia il seguente indirizzo nel tuo browser e segui le istruzioni: <br>http://www.omissis.com/canc_newsletter.php?posta=' . $mail[$k] . '&sec=' . $security[$k] .'&op=1</td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>';                             
            mail($mail[$k], strip_tags($titolo), $testo_news, $headers);
            $k++;
                        }

      $size = sizeof($mail);
      if ($size>0)
      {
            header("Location: contenuti.php?action=2&msg=1");
      }
      else
      {
            header("Location: contenuti.php?action=2");
      }

0
maxone
Asked:
maxone
  • 6
  • 5
  • 4
1 Solution
 
bevhostCommented:
Why don't you replace each paramater with a simple test string.
eg mail("me@mydomain","titolo","news");
One at a time to see which one makes it work ok.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
mail() function does not have correct parameters set to that,

better print all the values before you execute mail() function
0
 
maxoneAuthor Commented:
bevhost: I didn't get you? You think it's a problem in one of the email addresses stored in my database?

logudotcom: I did that, I echoed all the parameters before the mail() was executed. The email address is correct, the title is correct, the mail body is correct and also the headers
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Loganathan NatarajanLAMP DeveloperCommented:
dear maxone,

i am sure, you are passing wrong parameter to the mail function ... please check once again "email ID / title / headers ...

0
 
bevhostCommented:
or the subject has a newline char in it or a bad header
0
 
bevhostCommented:
try puting < > brackets around the email address.
0
 
maxoneAuthor Commented:
logu: did that again, the content is ok, the title is ok, the email address is present and correct and the headers are set

bevhost: I will try the brakets thing, the title is ok because I striptag it to avoid problems
0
 
Loganathan NatarajanLAMP DeveloperCommented:
Good, i think you are missing the headers part... try this,
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
 
/* To send HTML mail, you can set the Content-type header. */
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
 
/* additional headers */
$headers .= "To: Mary <mary@example.com>, Kelly <kelly@example.com>\r\n";
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";

Open in new window

0
 
bevhostCommented:
strip tag doesn't remove newlines does it?
If you printed it out, you'd see a newline it the output I assume.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
i would say you must include other headers parameter try with that
0
 
maxoneAuthor Commented:
I used the new headers set, still the same error, but I have seen that I missed to post the second part of the error earlier:

Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/m/a/x/maxone73/html/omissis/manager/spedisci_news.php on line 168

Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/m/a/x/maxone73/html/omissis/manager/spedisci_news.php on line 168

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/a/x/maxone73/html/omissis/manager/spedisci_news.php:168) in /home/content/m/a/x/maxone73/html/omissis/manager/spedisci_news.php on line 175
0
 
maxoneAuthor Commented:
and the winner is: Bevhost!
the new line tag was not visible printing the title line, so I used the interface that also the administrator is using and there was a new line.

thank you all!

Max
0
 
maxoneAuthor Commented:
the worst part will be telling the customer that he cannot write the newsletter subject on multiple lines as he always did...and it always worked!
0
 
bevhostCommented:
I wonder how many email reader client software supports multi line subject.?
0
 
maxoneAuthor Commented:
many! now that I removed the new lines ;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now