Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php嵌入图像已损坏_Php_Phpmailer - Fatal编程技术网

php嵌入图像已损坏

php嵌入图像已损坏,php,phpmailer,Php,Phpmailer,嗨,我正试图在电子邮件中嵌入一个图像,下面是我的php代码: $mail1->SMTPDebug = 2; $mail1->isSMTP(); $mail1->Host = 'smtp.gmail.com'; $mail1->SMTPAuth = true; $mail

嗨,我正试图在电子邮件中嵌入一个图像,下面是我的php代码:

$mail1->SMTPDebug = 2;                                 
$mail1->isSMTP();                                     
$mail1->Host = 'smtp.gmail.com';  
$mail1->SMTPAuth = true;                               
$mail1->Username = 'email@gmail.com';                
$mail1->Password = 'password';                           
$mail1->SMTPSecure = 'tls';                   
$mail1->Port = 587;
$mail1->setFrom('auto-reply@email.ca', '123');                  
$mail1->addAddress('email@gmail.com');     
$mail1->isHTML(true);                                 
$mail1->Subject = 'Thanks For Reaching us!';
$mail1->Body    = '
       <p> This is a test picture  <img src="img/logo.png"/>  </p>              
         ' ;

$mail1->send();
exit;

但是,它根本不显示图像,任何人都知道如何解决这个问题吗?

这将失败,因为它是一个相对路径,并且电子邮件没有相对的基本URL(这不是您针对嵌入图像的方式),所以它无法工作

$mail1->Body = '<p>This is a test picture <img src="img/logo.png"/></p>';

因为
cid
值匹配。使用绝对路径来确定从何处加载是值得的,您可以检查调用的返回值以确保它能够读取文件。

第二个参数是cid,您不使用它,您可能需要映像的完整服务器路径^,谢谢你回答我,我尝试了你说的方式,但是图片根本没有显示出来。你检查返回值和路径了吗?
$mail1->Body = '<p>This is a test picture <img src="img/logo.png"/></p>';
$mail1->Body = '<p>This is a test picture <img src="cid:two"/></p>';
$mail1->AddEmbeddedImage('img\logo.png', "two", "logo.png");