在电子邮件脚本中添加图像


Adding a image in a email script

我有一个电子邮件脚本,效果很好,但无法让图像与内容一起显示在电子邮件中。如何让图像显示在电子邮件中。我需要电子邮件显示在$template区域。

<?php
//Fetching Values from URL
$name = $_POST['name1'];
$email = $_POST['email1'];
$message = $_POST['message1'];
$contact = $_POST['contact1'];
//sanitizing email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
//After sanitization Validation is performed
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!preg_match("/^[0-9]{10}$/", $contact)) {
echo "<span>* Please Fill Valid Contact No. *</span>";
} else {
$subject = $name;
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers .= 'From:' . $email. "'r'n"; // Sender's Email
$headers .= 'Cc:' . $email. "'r'n"; // Carbon copy to Sender
$template = '<div style="padding:50px; color:white;">Hello ' . $name . ',<br/>'
. '<br/>Thank you...! For leaving your information with us.<br/><br/>'
. 'Name: ' . $name . '<br/>'
. 'Email: ' . $email . '<br/>'
. 'Contact No: ' . $contact . '<br/>'
. 'Message: ' . $message . '<br/><br/>'
. 'This is a Contact Confirmation mail.'
. '<br/>'
. 'We Will contact You as soon as possible . <br><br> Sincerely,<br>Prive Care Team.</div>';
$sendmessage = "<div style='"background-color:#7E7E7E; color:white;'">" . $template . "</div>";
// message lines should not exceed 70 characters (PHP rule), so wrap it
$sendmessage = wordwrap($sendmessage, 70);
// Send mail by PHP Mail Function
mail("cc-wp@hotmail.com", $subject, $sendmessage, $headers);
echo "Your Query has been received, We will contact you soon.";
}
} else {
echo "<span>* invalid email *</span>";
}
?>

在电子邮件(与任何HTML页面一样)中,有两种方法可以显示图像,一种是使用托管在Internet某处的图像<img src="src from the internet" />或者,您可以在base64中对图像数据进行编码并像这样嵌入<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />,这样电子邮件就可以自行(不依赖于Internet上的其他来源)包含,但会占用更多空间。