Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems with mail()

Posted on 2008-06-19
15
Medium Priority
?
231 Views
Last Modified: 2013-12-12
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
Comment
Question by:maxone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
15 Comments
 
LVL 19

Expert Comment

by:bevhost
ID: 21820828
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21820878
mail() function does not have correct parameters set to that,

better print all the values before you execute mail() function
0
 

Author Comment

by:maxone
ID: 21820941
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21820973
dear maxone,

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

0
 
LVL 19

Expert Comment

by:bevhost
ID: 21820988
or the subject has a newline char in it or a bad header
0
 
LVL 19

Expert Comment

by:bevhost
ID: 21821000
try puting < > brackets around the email address.
0
 

Author Comment

by:maxone
ID: 21821009
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21821033
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
 
LVL 19

Accepted Solution

by:
bevhost earned 500 total points
ID: 21821038
strip tag doesn't remove newlines does it?
If you printed it out, you'd see a newline it the output I assume.
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21821043
i would say you must include other headers parameter try with that
0
 

Author Comment

by:maxone
ID: 21821068
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
 

Author Comment

by:maxone
ID: 21821088
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
 

Author Comment

by:maxone
ID: 21821190
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
 
LVL 19

Expert Comment

by:bevhost
ID: 21821266
I wonder how many email reader client software supports multi line subject.?
0
 

Author Comment

by:maxone
ID: 21821288
many! now that I removed the new lines ;)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question