如何在电子邮件正文中嵌入和映像?

时间:2015-03-11 08:25:20

标签: php email-attachments

我的代码在下面,所以我想知道我能在身体上做些什么来发送带有图像的邮件?

include('SMTPconfig.php');
include('SMTPclass.php');

$from ="pilotn@ann7.com";
$to =$email; 

$subject="Your new password";  

$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; 

$body = "Dear $name\n\n".
"You are invited to register for SATY2015 RSVP log in to http://www.ann7.com/saty2015/index.php to register.\n\n". 
"Your username is: $email\n\n". 
"Your password is: $pass\n\n"; 

$headers = "From: $from \r\n"; 
$headers .= "Reply-To: $from \r\n";

$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $to, $subject, $body, $headers);   
$SMTPChat = $SMTPMail->SendMail();

if($SMTPChat)
{
    $msg="<font color='#63a634'>An email has been sent containing login information. </font>";
}
else
{
    $msg="The error occured and your email has not sent containing the information.";
}

1 个答案:

答案 0 :(得分:0)

将代码HTML包含在变量中,如下所示:

include('SMTPconfig.php'); include('SMTPclass.php');

$from ="pilotn@ann7.com"; $to =$email;

$subject="Your new password";
$theImage="<img src='http://yourdomain.com/yourimage.jpg'>";

$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

$body = "Dear $name\n\n". "$theImage You are invited to register for SATY2015 RSVP log in to http://www.ann7.com/saty2015/index.php to register.\n\n". "Your username is: $email\n\n". "Your password is: $pass\n\n";

$headers = "From: $from \r\n"; $headers .= "Reply-To: $from \r\n";

$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $to, $subject, $body, $headers);
$SMTPChat = $SMTPMail->SendMail(); if($SMTPChat) { $msg="An email has been sent containing login information. "; } else { $msg="The error occured and your email has not sent containing the information."; }