NYCPHP Meetup

NYPHP.org

[nycphp-talk] mail problems

Michael Southwell michael.southwell at nyphp.com
Tue Mar 27 18:35:04 EDT 2007


I am having a baffling problem with a script that sends an html email.
It seems to work sometimes and not at other times. My (unhappy) client
is seeing headers when she gets anything. Multiple recipients seem to
handled randomly. What can you see here that's wrong? I have tested
$addresses and it is the properly comma-delimited string.
============================
......
$addresses = $_POST['addresses'];
$addresses = str_replace( ' ', '', $addresses );
$addresses = str_replace( "\r\n", '', $addresses );
$addresses = str_replace( "\n", '', $addresses );

$to = 'Undisclosed Recipients <ronnie at ronnieschultz.com>';
$subject = 'Spring Arrives';

$headers = "From: ronnie at ronnieschultz.com\n";
$headers .= "Bcc: $addresses\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\n\n";
$headers .= '
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <x-html>
          <head>
          <style>
                  #content {position:absolute; top:100px; left:25px; }
                  a {text-decoration:none;}
                  .fallback a:link,a:visited,a:hover {color:#00f;}
                  p {font-family:sans-serif;font-size:.8em; margin-left:2em; }
          </style>
          </head>

          <body>

          <p class="fallback">
          [If you are not seeing graphics in this message, please 
click <a href="http://dneba.com/rs/2007/sp07.php">here</a>.]<br />
          </p>

          <div id="content">
          <a href="http://ronnieschultz.com">
          <img src="http://lauratheodore.com/test/sp07.jpg" 
width="750" height="1050" border="0" alt="We are pleased to offer you 
a Spring Photography Session" title="We are pleased to offer you a 
Spring Photography Session" />
          </a>
          </div>

          </body>
';

if ( ! mail( $to, $subject, '', $headers ) ) {
          exit( 'There has been an error sending your mail. Please 
report this.' );
}
else {
          $addresses = str_replace( ',', '<br />', $addresses );
          echo '<p>The card has been sent to:<br />' . $addresses . '</p>';
} // no error sending
====================

You can try this for yourselves at http://lauratheodore.com/test/xms.php.



Michael Southwell, Vice President for Education
New York PHP
http://www.nyphp.com/training - In-depth PHP Training Courses





More information about the talk mailing list