Trying to send html mail via PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Trying to send html mail via PHP

Post 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); 
}  
?>
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post 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?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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.
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post 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);
?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried sending a simple email to yourself? Does that work?

Mac
Post Reply