如何在通过phpmailer发送给gmail的电子邮件的最顶部放置网站徽标和身份图像设计

时间:2019-07-17 15:32:43

标签: phpmailer

[在此处输入图片描述] [1]我正在发送密码恢复邮件,并且我使用了html标记来支持跨平台。我将图像放在顶部的邮件中的正确位置。但是,图像以附件的形式放置在邮件下方,没有css样式,并且不在页面顶部的表格行中。如何确保图片放在gmail顶部而不是底部?

我使用了phpmailer AddEmbeddedImage('../../ img / kokwo_full.png','{$ site}','{$ site} .png')。


$subject="Password Reset Request - {$site}";

$message="
<table  width='100%' style=' background:#f2f2f2; margin:0px; margin:0px 0px; color:#fff; font-family: Arial, sans-serif; font-size:12px; font-weight:bold; padding:0% 2%'>
<tr style='background:#fff;'>
<td colspan='2'><img src='{$http}://{$website}/img/kokwo.png' style='background:#4885ed; height:60px'/></td>
</tr>

<tr style='height:140px;'>
<td colspan='2' style='color:#000;text-align:center; font-size:32px'> </td>
</tr>

<tr>
<td colspan='2' style='color:#000;text-align:center; font-size:32px; border-bottom:1px solid #000'> Hi {$user_name},</td>
</tr>
<tr style='  height:90px;'>
<td colspan='2' style='color:#000; font-size:18px'>Instant password change
<p style='color:#000; font-size:10px'>{$email}</p></td>
</tr>
<tr style=' color:#808080; '>
<td colspan='2' style='color:#808080; font-size:18px'>Click on this button</td>

</tr>

<tr style='  height:30px;'>
<td colspan='2' style='text-align:center;'>
<form action='{$http}://{$website}reset' method='post' class='regi' enctype='multipart/form-data'>
<input type='text'  name='user_id' value='{$user_id}' style='display:none;'/>
<button type='submit' style='background:#00A9E0; color:#fff; padding: 10px;
  font-size: 18px;
 border: none;
  border-radius: 5px;
    width: 89%;
    margin:25px 3%'   name='reg_user' >Change your password on ".ucwords($site)." </button>
</form>
</td>
  </tr>
<tr style='height:80px;'>
<td colspan='2'> </td>
</tr>
<tr style='height:30px; background:#4885ed;'>
<td colspan='2'></td>
</tr>

</table>
";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['reset-password'])) {

require '../../PHPMailer/src/Exception.php';
require '../../PHPMailer/src/PHPMailer.php';
require '../../PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.{$site}.com"; // "ssl://smtp.gmail.com" didn't worked

$mail->SMTPAuth = true;
 $mail->IsHTML(true); // if you are going to send HTML formatted emails




$mail->Username = $my_mail;
$mail->Password = $my_password;



$mail->From = $my_mail;
$mail->FromName = $fromname;

$mail->addAddress($email, $user_name);


$mail->addReplyTo($my_mail, $fromname);
$mail->Sender=$my_mail;

//Provide file path and name of the attachments



$mail->Subject = $subject;
$mail->AddEmbeddedImage('../../img/kokwo_full.png', '{$site}', '{$site}.png');
$mail->Body = $message;
$mail->AltBody=$subject;
$mail->Send();


if (!$mail) {

        array_push($errors, "<div class='error'><p>
        Could not be delivered to {$email},please try again
            .</p></div>");



    } else {
     array_push($errors, "<div class='success'><p>
             Check inbox or spam folder  at {$email}.</p></div>");


        }
}
```what i want to achieve[What I got][2]


  [1]: https://kokwo.com/img/stack/real.jpg
  [2]: https://kokwo.com/img/stack/fake.jpg

1 个答案:

答案 0 :(得分:0)

您已将其附加为嵌入式图像,但实际上并未在模板中使用它。

addEmbeddedImage的第二个参数是内容标识符cid。一个单独的问题是,您已经用单引号引起来了字符串,因此不会进行变量插值-这可能不是您想要的。

因此,如果您的通话看起来像这样:

$mail->addEmbeddedImage('../../img/kokwo_full.png', 'kokwo', 'kokwo.png').

您将在HTML中使用该图像,如下所示:

<img src="cid:kokwo" style="background:#4885ed; height:60px">

请注意,URL cid:部分后面的字符串与您传递给cid的{​​{1}}值完全匹配。