如何在PHP中的电子邮件正文中发送徽标?

时间:2018-10-26 20:13:21

标签: php html phpmailer

我正在附上我的电子邮件代码。我想在我的身体部分添加图片,并在此代码中显示一条消息。

require_once "../lib/Mail-1.4.1/Mail.php";

$from = 'someone@gmail.com';
$to = $mail;
$subject = 'Account Confirmation';
$body = 'Thanks for registering yourself, your login credentials are as 
follows;'."\r\n".'Your User Name is: '.$uname.''."\r\n".'Your Password is: 
'.$pass1.'';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
 );

$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'someone@gmail.com',
'password' => '12345678'
 ));
 $mail = $smtp -> send($to, $headers, $body);

if(PEAR::isError($mail)){
echo '<p>'.$mail->getMessage().'</p>';   
}
else{
   echo "<script>alert('Successfully Registered! Your credentials have been 
sent on email that you have given in the form')</script>";
 }

这是我的电子邮件代码,我想在其中添加图像/徽标。

1 个答案:

答案 0 :(得分:1)

用于嵌入图像AddEmbeddedImage

您还可以将图像添加为带有My-photo内容ID的嵌入式附件,您可以使用<img src="cid:my-photo" alt="my-photo">在HTML正文中访问它。

详细说明,这是添加嵌入式附件的功能:

$mail->addEmbeddedImage($filename, $cid);