PHP HTML email
Posted: Tue May 20, 2008 3:20 pm
Sorry if this has been hashed and re-hashed. I looked in previous posts and didn't see the topic covered. I'm new to PHP, and am experimenting with a snippet of code that I googled. I want to send a PHP generated, HTML formatted email. The code that I have is ...
<?php
$to = "xx@ccc.com";
$subject = "My HTML email test";
$headers = "From: xx@ccc.com\r\n";
$headers .= "Reply-To: xx@ccc.com\r\n";
$headers .= "Return-Path: xx@ccc.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<table><tr><td>";
$message .= "hello<br>";
$message .= "<img src='image.jpg'>";
$message .= "</td></tr></table>";
$message .= "</body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
I've filled in the headers with appropriate information and sent the email to myself. The table constructed fine and the word "hello" appeared, but I get a broken link icon where the image should be. I've tripled checked the image file name and compared it to what I have in my code. I've tried putting the image in it's own folder and directing the script there. Nothing's worked.
Suggestions?
Thanks in advance -
sleepydad
<?php
$to = "xx@ccc.com";
$subject = "My HTML email test";
$headers = "From: xx@ccc.com\r\n";
$headers .= "Reply-To: xx@ccc.com\r\n";
$headers .= "Return-Path: xx@ccc.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<table><tr><td>";
$message .= "hello<br>";
$message .= "<img src='image.jpg'>";
$message .= "</td></tr></table>";
$message .= "</body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
I've filled in the headers with appropriate information and sent the email to myself. The table constructed fine and the word "hello" appeared, but I get a broken link icon where the image should be. I've tripled checked the image file name and compared it to what I have in my code. I've tried putting the image in it's own folder and directing the script there. Nothing's worked.
Suggestions?
Thanks in advance -
sleepydad