Solved

Problems with mail()

Posted on 2008-06-19
15
218 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php email 2 26
simplest php form 3 59
<? versus <?php 5 36
Configuring a checkbox in CSS and php 18 31
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

21 Experts available now in Live!

Get 1:1 Help Now