简体   繁体   English

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

[英]How to send logo in the body of email in php?

I am attaching my email code.我附上了我的电子邮件代码。 I want to add an image in my body section with a message in this code.我想在我的正文部分添加一个图像,并在此代码中添加一条消息。

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>";
 }

this is my email code, in body I want to add an image/logo.这是我的电子邮件代码,在正文中我想添加一个图像/徽标。

Use for embedding image AddEmbeddedImage用于嵌入图像AddEmbeddedImage

you can also add an image as inline attachment with the content ID of my-photo, you would access it within the HTML body using <img src="cid:my-photo" alt="my-photo"> .您还可以使用 my-photo 的内容 ID 添加图像作为内嵌附件,您可以使用<img src="cid:my-photo" alt="my-photo">在 HTML 正文中访问它。

In detail, here is the function to add an embedded attachment:详细来说,这里是添加嵌入式附件的功能:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM