Page 1 of 1

Trying to send html mail via PHP

Posted: Mon Dec 15, 2003 11:38 am
by Perfidus
I have this code whit which I'm trying to send an emial formated with HTML, the problem is that inside the HTML there are some PHP tags embeded and I think that's the reason it doesn't work even though maybe there 1 or 2 thousand reasons more:

Code: Select all

<?php 
/* recipients */ 
$to  = "whatever@whatever.com" . ", " ; // note the comma 
$to .= "whatever@whatever.com"; 

/* message */ 
$message = " 
<body> 
<html> 
<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#CCCCCC'> 
  <tr> 
    <td><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'> 
        <tr> 
          <td colspan='2'><div align='right'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><strong>N&uacute;mero 
              de referencia:</strong> ".echo $codigo."<img src='http://www.whatever.com/images/1nada.gif' width='10' height='9'></font></div></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: whatever <whatever@whatever.com>, whatever <whatever@whatever.com>\r\n"; 
$headers .= "From: Customer <$email>\r\n"; 


/* and now mail it */ 
mail($to, $subject, $message, $headers); 
}  
?>

Posted: Mon Dec 15, 2003 11:52 am
by microthick
So you never receive the email?

Or it doesn't contain the html?

Have you tried removing the 2nd recipient of the email to see if it sends then?

Posted: Mon Dec 15, 2003 1:40 pm
by dull1554
and if you dont recieve the email, check to see if you have sendmail on your server......or at the least a pop3 server.....hope u get it to work.

Posted: Mon Dec 15, 2003 3:10 pm
by Perfidus
What happened was not that message was not sent, the problem was that I was reported some errors from PHP, now they are solved, so I get no errors, but e-mail is never sent.
What can it be?

Code: Select all

/* recipients */
$to  = "whatever@whatever.com" . ", " ; // note the comma
$to .= "whatever@whatever.com";

/* subject */
$subject = $Ref;

/* message */
$message = "
<body>
<html>
<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#CCCCCC'>
  <tr> 
    <td><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'>
        <tr>
          <td colspan='2'><div align='right'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><strong>N&uacute;mero 
              de referencia:</strong> ".$codigo."<img src='http://www.whatever.com/images/1nada.gif' width='10' height='9'></font></div></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: Belén <contact@whatever.com>, Ignacio <whatever@whatever.com>\r\n";
$headers .= "From: Customer <$email>\r\n";


/* and now mail it */
mail($to, $subject, $message, $headers);
?>

Posted: Mon Dec 15, 2003 8:20 pm
by DuFF
Change this

Code: Select all

<?php

$to  = "whatever@whatever.com" . ", " ; // note the comma
$to .= "whatever@whatever.com";

?>
to your email address. So something like:

Code: Select all

<?php
$to  = "Perfidus@yoursite.com";
?>
Guess you forgot to edit that part :wink:

Posted: Tue Dec 16, 2003 2:57 am
by twigletmac
Have you tried sending a simple email to yourself? Does that work?

Mac