Jump to content

Display image in email


herghost

Recommended Posts

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 <[email protected]>";
$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

Link to comment
https://forums.phpfreaks.com/topic/180639-display-image-in-email/
Share on other sites

Hi,

 

Thanks,

 

I know have this:

 

$sender = "Stockluck Registration Success <[email protected]>";
$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 <[email protected]>";
$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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.