herghost Posted November 7, 2009 Share Posted November 7, 2009 Hi all, I am getting very frustrated with this and need some help! I am sending an email to the user when they have registered on my site, the code is as follows: $from = "StockLuck <reg@stockluck.com.au>"; $to = $email; $subject = "Registration Success!"; $message = '<img src="images/newlogo.jpg" width="500" height="60" alt="logo" /> Dear ' . $first_name . ' Thank you for registering at www.stockluck.com.au Your Username is ' . $username . ' You can now login at http://www.stockluck.com.au Good Luck! StockLuck.com.au'; $host = "ssl://mail.stockluck.com.au"; $port = "465"; $username = "reg+stockluck.com.au"; $password = "***"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $message); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else {?> The email is sending fine, however the html is not being displayed(the image), the email comes through like so: <img src="images/newlogo.jpg" width="500" height="60" alt="logo" /> Dear David Thank you for registering at www.stockluck.com.au Your Username is Dave You can now login at http://www.stockluck.com.au Good Luck! StockLuck.com.au The links work and are being seen as clickable links. I am guessing that you must have to tell the client that its a html mail being sent but I have no idea how to set the mime type! Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/ Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2009 Share Posted November 7, 2009 since your sending a email all your images and links should be absolute http://... full paths. Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953010 Share on other sites More sharing options...
herghost Posted November 7, 2009 Author Share Posted November 7, 2009 Still same problem, email looks like this: <img src="http://www.stockluck.com.au/images/newlogo.jpg" width="500" height="60" alt="logo" /> Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953013 Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2009 Share Posted November 7, 2009 it should come which email client your viewing it in, some email clients do not display images until you click on a button above saying display images (like google) Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953016 Share on other sites More sharing options...
herghost Posted November 7, 2009 Author Share Posted November 7, 2009 I think the problem is with the mime type, I am viewing in gmail and the button is not there. I think the email is sending as plain text Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953027 Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2009 Share Posted November 7, 2009 Ah yes you will have to send it as text/html Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953028 Share on other sites More sharing options...
mikesta707 Posted November 7, 2009 Share Posted November 7, 2009 You have to set the mime and content type to support html emails. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953029 Share on other sites More sharing options...
herghost Posted November 7, 2009 Author Share Posted November 7, 2009 Hi, Thanks, I know have this: $sender = "Stockluck Registration Success <reg@stockluck.com.au>"; $recipient = $email; $subject = "Registration Success!"; $text = 'Dear ' . $first_name . ' Thank you for registering at www.stockluck.com.au Your Username is ' . $username . ' You can now login at http://www.stockluck.com.au Good Luck! StockLuck.com.au'; $html = '<html><body><p><img src="http://www.stockluck.com.au/images/newlogo.jpg" width="500" height="60" alt="logo" /><br><br> Dear ' . $first_name . ' <br /> <br /><br /> Thank you for registering at www.stockluck.com.au<br /> <br /> Your Username is ' . $username . '<br /> <br /> You can now login at http://www.stockluck.com.au<br /> <br /> Good Luck!<br /> StockLuck.com.au </p></body></html>'; $crlf = "\n"; $headers = array( 'From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject ); $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $body = $mime->get(); $headers = $mime->headers($headers); $host = "ssl://mail.stockluck.com.au"; $port = "465"; $username = "reg+stockluck.com.au"; $password = "**"; $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($recipient, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { ?> However the page will no longer display and I am getting no errors get the header up but no more. The full page code is: <?php session_start(); error_reporting(0); require_once "Mail.php"; include('Mail\mime.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Stockluck.com.au - Australia's Favourite Stock Game - Cash Prizes</title> <meta name="keywords" content="" /> <meta name="description" content="" /> </head> <body> <?php include('common/header1.php'); include 'common/dbconnect.php'; $username = $_POST['username']; $password = sha1($_POST['password']); $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $query = "INSERT INTO users (username, password) VALUES ('$username', '$password')"; $result = mysql_query($query, $conn) or die(mysql_error()); $query = " INSERT INTO users_details (username, first_name, last_name, email, city, state) VALUES ('$username', '$first_name', '$last_name', '$email', '$city', '$state') "; $result = mysql_query($query, $conn) or die(mysql_error()); $query = "INSERT INTO users_stocks (username) VALUES ('$username') "; $result = mysql_query($query, $conn) or die(mysql_error()); $_SESSION['logged'] = 1; $_SESSION['username'] = $username; //send email $sender = "Stockluck Registration Success <reg@stockluck.com.au>"; $recipient = $email; $subject = "Registration Success!"; $text = 'Dear ' . $first_name . ' Thank you for registering at www.stockluck.com.au Your Username is ' . $username . ' You can now login at http://www.stockluck.com.au Good Luck! StockLuck.com.au'; $html = '<html><body><p><img src="http://www.stockluck.com.au/images/newlogo.jpg" width="500" height="60" alt="logo" /><br><br> Dear ' . $first_name . ' <br /> <br /><br /> Thank you for registering at www.stockluck.com.au<br /> <br /> Your Username is ' . $username . '<br /> <br /> You can now login at http://www.stockluck.com.au<br /> <br /> Good Luck!<br /> StockLuck.com.au </p></body></html>'; $crlf = "\n"; $headers = array( 'From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject ); $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $body = $mime->get(); $headers = $mime->headers($headers); $host = "ssl://mail.stockluck.com.au"; $port = "465"; $username = "reg+stockluck.com.au"; $password = "*****"; $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($recipient, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { ?> ?> <div id="page"> <!-- start content --> <div id="content"> <div class="post"> <p class="meta"> </p> <h1 class="title">Registration Results <img src="./images/stockimages/0.jpg" height="80" width="80" alt="stockluck" /></h1> <div class="entry"> <p><span style=" color:#3F0">Congratulations!</span></p> <p>You may now login with these details:</p> <p>Username = <?php echo $_SESSION['username'];?>; <p>Password = Your Choosen Password</p><br /> <p>These details have also been sent to <?php echo $email ;?></p> <br /> Thanks for joining and good luck! </div> </div> </div> <?php } ?> <?php include('include/sidebar_0.php'); include('common/footer.php'); ?> <!-- start page --> <!-- end content --> <!-- start sidebar --> </div> <!-- end page --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953031 Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2009 Share Posted November 7, 2009 your error reporting is set to 0 line 3 comment that and you might see the error Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953033 Share on other sites More sharing options...
herghost Posted November 7, 2009 Author Share Posted November 7, 2009 ha ha Fatal error: Class 'Mail_mime' not found in /home/stockluc/public_html/indexreg2.php on line 93 what dumbass forgot to install Mail_Mime PEAR package!! Quote Link to comment https://forums.phpfreaks.com/topic/180639-display-image-in-email/#findComment-953035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.