Solved

Problems with mail()

Posted on 2008-06-19
15
217 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
  • 6
  • 5
  • 4
15 Comments
 
LVL 19

Expert Comment

by:bevhost
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
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
Comment Utility
or the subject has a newline char in it or a bad header
0
 
LVL 19

Expert Comment

by:bevhost
Comment Utility
try puting < > brackets around the email address.
0
 

Author Comment

by:maxone
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
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 125 total points
Comment Utility
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
Comment Utility
i would say you must include other headers parameter try with that
0
 

Author Comment

by:maxone
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I wonder how many email reader client software supports multi line subject.?
0
 

Author Comment

by:maxone
Comment Utility
many! now that I removed the new lines ;)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now