Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I use phpmailer() to send an html email containing an image. I've tried every possible way I know but can't seem to get it done. This is the code I am using:


PHP
require("class.phpmailer.php");

$msg = $_POST['msg'];
$subject = $_POST['subject'];


$mail = new PHPMailer();
#$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "branddesignexpress.com/cpanel";
$mail->SMTPAuth = true;
$mail->Username = 'admin@example.com';
$mail->Password = 'xxxxxx';

$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";
$mail->Sender="mailer@example.com";
$mail->AddReplyTo("replies@example.com", "Replies for my site");

$mail->AddAddress("plasteezy@yahoo.com");
$mail->Subject = $subject;

$mail->IsHTML(true);
$mail->AddAttachment('http://www.branddesignexpress.com/images/homepage_mainimage.jpg', 'homepage_mainimage.jpg');
$mail->AddEmbeddedImage('homepage_mainimage.jpg', 'logoimg', 'homepage_mainimage.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg
$mail->Body = $msg;
$mail->AltBody="This is text only alternative body.";

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
   echo "Letter is sent";
}




I always get the following error: SMTP Error: Could not connect to SMTP host. Error sending: SMTP Error: Could not connect to SMTP host.
Posted
Updated 8-Nov-10 3:31am
v4

1 solution

it could be a problem with the way you've configured the SMTP server in your script:

$mail->Host = "branddesignexpress.com/cpanel";


SMTP config usually looks more like:

$mail->Host = "mail.myfavouritehostingcompany.com";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900