Why won't my images display in html email? - php

I have a script for sending HTML email messages which works fine for text and html tags but I cannot figure out why my images wont display.
function sendHtmlEmail($email, $content, $message_content){
$to = "$email";
$subject = "AeroBLOG - $content";
$message = "
<HTML>
<HEAD>
<TITLE>$subject</TITLE>
<META http-equiv='content-type' content='text/html; charset=utf-8' />
<STYLE>
</HEAD>
<BODY>
$message_content
</BODY>
</HTML>
";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
$headers .= 'From: <do-not-reply#aeroblog.tk>' . "\r\n";
if(mail($to,$subject,$message,$headers)){return true;}else{return false;}
}
call to function:
$message="<IMG src=\"http://aeroblog.tk/img/VerificationEmail.png\" alt=\"copy & paste this link into your browsers navigation bar: http://.........\" width=\"1024px\" height=\"768px\">";
sendHtmlMail("myemail#example.com","Subject",$message);
Here is the complete email which is returned including headers:
Delivered-To: oneal.michaels#gmail.com
Received: by 10.182.154.35 with SMTP id vl3csp1831038obb;
Sun, 6 Dec 2015 16:26:01 -0800 (PST)
X-Received: by 10.13.213.14 with SMTP id x14mr19939281ywd.229.1449447961510;
Sun, 06 Dec 2015 16:26:01 -0800 (PST)
Return-Path: <a6602671#srv10.000webhost.com>
Received: from postlady.000webhost.com (smtp5.000webhost.com. [31.170.163.248])
by mx.google.com with ESMTP id j63si14327386ywf.69.2015.12.06.16.26.01
for <oneal.michaels#gmail.com>;
Sun, 06 Dec 2015 16:26:01 -0800 (PST)
Received-SPF: pass (google.com: domain of a6602671#srv10.000webhost.com designates 31.170.163.248 as permitted sender) client-ip=31.170.163.248;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of a6602671#srv10.000webhost.com designates 31.170.163.248 as permitted sender) smtp.mailfrom=a6602671#srv10.000webhost.com
Received: by postlady.000webhost.com ([000webhost.com Mail Server], from userid 99)
id 59C5B602FC; Mon, 7 Dec 2015 00:26:01 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on
postlady.000webhost.com
X-Spam-Level: ****
X-Spam-Status: No, score=4.6 required=7.0 tests=BODY_URI_ONLY,
HTML_IMAGE_ONLY_08,HTML_IMAGE_RATIO_02,HTML_MESSAGE,HTML_SHORT_LINK_IMG_1,
MIME_HTML_ONLY,TVD_RCVD_SPACE_BRACKET,T_RP_MATCHES_RCVD autolearn=disabled
version=3.3.2
Received: from srv10.000webhost.com (srv10.000webhost.com [31.170.160.74])
by postlady.000webhost.com ([000webhost.com Mail Server]) with ESMTP id 9924B602FB
for <oneal.michaels#gmail.com>; Mon, 7 Dec 2015 00:25:26 +0000 (UTC)
Received: by srv10.000webhost.com (Postfix, from userid 6602671)
id 929B018B5C7; Sun, 6 Dec 2015 19:25:26 -0500 (EST)
To: oneal.michaels#gmail.com
Subject: AeroBLOG - Verification Email: Welcome, MikeIsMyName
X-PHP-Script: aeroblog.tk/sendVerificationEmail.php for 172.73.244.114
MIME-Version: 1.0
Content-type: text/html; charset: utf8
From: <do-not-reply#aeroblog.tk>
Message-Id: <20151207002526.929B018B5C7#srv10.000webhost.com>
Date: Sun, 6 Dec 2015 19:25:26 -0500 (EST)
<HTML>
<HEAD>
<TITLE>AeroBLOG - Verification Email: Welcome, MikeIsMyName</TITLE>
<META http-equiv='content-type' content='text/html; charset=utf-8' />
<STYLE>
</HEAD>
<BODY>
<IMG src="http://aeroblog.tk/img/VerificationEmail.png" alt="copy & paste this link into your browsers navigation bar: http://........." width="1024px" height="768px">
</BODY>
</HTML>

Some e-mail servers blocks images contents from some e-mails. Did you try looking at the "source code" of the e-mail? In gmail you can find it by clicking in Show Original Message. Another thing that can be happening is that the client is not able to access the image file in your website, or the image link is incorrect.
If you still have trouble with this, I recommend using PHPMailer to send your e-mails. It's really easy to use and has a lot of functions, such as SSL and TLS or Attachments in e-mails.

Related

PHPMailer no longer processing multipart email correctly

I've been using a PHPMailer script for years sending emails to my group. Everything was working great up until last week. Now when I send an email the multi-part is fully displayed as plain text. Here is my PHP script:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '/fullpath/public_html/tmp/PHPmailer.php';
require '/fullpath/public_html/tmp/SMTP.php';
require '/fullpath/public_html/tmp/Exception.php';
$body = $_POST['msgText'];
$mail = new PHPMailer();
$mail->setFrom('MY WEB SITE EMAIL', 'ME');
$mail->addReplyTo('MY EMAIL', 'ME');
$mail->addAddress('MY EMAIL', 'ME');
$mail->Subject = $_POST['subjectText'];
$mail->isHTML(true);
$mail->SMTPDebug = 2;
$mail->Body = $body;
$mail->CharSet = 'UTF-8';
$a = $_POST['toText'];
// For output display
echo "<!DOCTYPE html>\n<html lang=en><head><title>My Test PHP Mailer</title></head>\n<body>\n<h1>My Test PHP Mailer</h1>\n<h4>Sending Emails to:</h4>\n<ul>";
foreach ($mail->parseAddresses($a) as $address) {
$mail->addBCC($address['address'], $address['name']); // for release
// $mail->addAddress($address['address'], $address['name']); // for testing
echo "<li>Name: " . $address['name'] . " - address: [" . $address['address'] . "]</li>\n";
}
echo "</ul>\n";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo "<br>" . $_POST['toText'];
} else {
echo "<form><textarea name=ta>" . $body . "'></textarea></form>";
}
echo "<p><a href='index.php'>Back to index.php</a></p>\n</body>\n</html>";
?>
And my email is showing up like this:
This is a multi-part message in MIME format.
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro
Content-Type: text/plain; charset=us-ascii
Good luck to all, and thanks for participating,
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro
Content-Type: text/html; charset=us-ascii
<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></HEAD>
<BODY bgColor="#ffffff">
<div style="max-width:800px;border:1px solid #666666; padding:9px; background-color:white;">
<DIV><FONT face="Arial" color="#000080" size="6"><B><I>NFL
<FONT color="#C80000">Challenge</FONT> 2022</I></B></FONT></DIV>
<DIV><FONT face="Arial, Helvetica" color="#ff0000" size="4"><B>Hey Sportsfans,</B></FONT></DIV>
<br>
<DIV><FONT face="Arial" size="2">Good luck to all, and thanks for participating,</FONT></DIV>
<br>
</DIV></div>
</BODY>
</HTML>
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro--
I haven't made any changes in the last week. Why would the emails be sent as simply text and not do the multi-part encoding? This output is the same for all mail clients.
I have searched the internet for the last week and can't find anything that helps. I did update to the latest version of PHPMailer to see if that would fix the problem, but it still remains. I want the email to be sent as HTML and not have the raw details going out to all my friends.
Any suggestions, opinions or dumb looks appreciated.
==============[ UPDATE ]=================
I was asked to specify more details on my problem. When I tried initially, Stackoverflow gave me an error that this was a spam submission. So I'm going to try again and redact some details to hopefully avoid that error.
First - the email is being sent using PHPMailer 6.1.1
Second - the email clients receiving the emails that I have been able to test are: Gmail, Outlook, and Yahoo Mail.
Third - I was asked to share the raw source of the email (this is where I hope I can avoid the 'spam' error).
This is the last working email I sent, as reported from Gmail "show original":
Subject: NFL Challenge 2022 - Week 18 Reminder
X-PHP-Script: xxxxxxxxxxxx/file.php for 162.252.247.224
X-PHP-Originating-Script: 1002:PHPmailer.php
Date: Fri, 6 Jan 2023 01:02:03 +0000
From: NFL Challenge <me#myserver>
Message-ID: <GdssaiyhOGwE5lgWdOnRMleJbhKIfeZQPc4TpJB74#www.starbase47.com>
X-Mailer: PHPMailer 6.1.1 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="b1_GdssaiyhOGwE5lgWdOnRMleJbhKIfeZQPc4TpJB74"
Content-Transfer-Encoding: 8bit
X-CMAE-Envelope: MS4xfNLwjf/lI+ECbHq2uNTaPo2pDBlT0LgWHZfm+1mtCGh1qLdFoViGjgSHemmT9C8buRCOrt1A4pAvnGulYNkPiO6cJBSDRVv2s9yqB3tUM/GOH02Idbpt 4uA8x2WkhDDGrE1gBk+cE3ZeAWqXwfQWDQznYq5N7InVD9s4UlutNmMlACjSidhnEIrzVJHFZsR3gvGOSiEZDf8Xg4jjk51comuqnF4hLvF9slMWKexfPYfp 6Xxsb7BqWoHfbmSTB0WrMR6wzG3e0ybFGe3HDiMIPPCsHfCHUzaLjXMSfUCI8xcbnScfTz9t/00yLtSwLj4nu+sganzgBI433vpvFj28Aw7bDlm4K0iERspz shEaDRpZwHKD44xwCTSsa/zjvrXAdsOo39EuWLtn25QSOT3QYuEKmpe4M1mMGS6BH/oP3rxUGu89rDzc7fBcav7MtnNLI7Wz2kWAnBvuyrZWhKM/vBzLUUd/ uWtz/nhTNzzItSy1rm8ObR+cm6RuWil0uilXF9nF/gg5TzFOixzNgTuvexbclXCl198ACnro7gQfxMM47NeRuZkhQUjjOuhm+k0TeJyRKWD7S1ujA3qfndH/ 8LI=
--b1_GdssaiyhOGwE5lgWdOnRMleJbhKIfeZQPc4TpJB74
Content-Type: text/plain; charset=us-ascii
NFL
Challenge 2022
Hey Sportsfans, ...
This is the source of the email that didn't format correctly, again from Gmail "show source".
Subject: NFL Challenge 2022 - Playoffs Test
X-PHP-Script: www.starbase47.com/mytest_mail.php for 162.252.247.224 X-PHP-Originating-Script: 1002:PHPmailer.php
Date: Thu, 12 Jan 2023 21:33:09 +0000 From: NFL Challenge <me#myserver> Message-ID: <5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro#www.starbase47.com> X-Mailer: PHPMailer 6.1.1 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Type: multipart/alternative;
boundary="b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro" Content-Transfer-Encoding: 8bit
Message-Id: <E1pG5C9-0006pY-1D#192.222.167.72.host.secureserver.net>
From: me#myserver
X-CMAE-Envelope: MS4xfI/De/t+kmwbb6eY2xWVi89UxsAiJ5qMwBEnzqpJBSwnrpHKLYrLpRjMnFUNxqZVwAckeapMXSEzXsK71DSiMO5WP0VZxM0iNr0qMiD/lOxS2Sp5+Vb0 4nUe/KgwmKZcA8v6BUI5N0fFqt5Ha2nrzlg4ouBiPrZTTYgrTQ+UQoHWyWWl/LWrhDX5AUYdRYL/DI0Q7u5H+LjjhdKhAOdTeKAPsa+EEkVMxWbX/z27TF2m jzATQVQbCe7u4en0+gEgDg==
This is a multi-part message in MIME format.
--b1_5S1Pr6ILOHSPuOiGgJGQzPfIPsBjnsOmX6MAuoro
Content-Type: text/plain; charset=us-ascii
NFL
Challenge 2022
Hey Sportsfans, ...
If you need me to share more details (like from another client, or the raw PHPMailer code that I have on my server) please let me know.
Thank you in advance - Einstein47

php mail using mailgun smtp blocked by gmail; error RFC 5322

I am getting the following intermittent error that has started in the last 24 hours from gmail servers (When sending to gsuite accounts or gmail accounts). It doesn't happen to all messages. Even the same message failed once and then worked later. I am looking for a way to fix this. I am not sure if it is the headers or something gmail did as a mistake.
I have a dedicated IP with mailgun and aren't getting any other errors except gmail.
This is the error:
5.7.1 [69.72.33.194 11] Our system has detected that this message is 5.7.1 not RFC 5322 compliant: 5.7.1 'From' header is missing. 5.7.1 To reduce the amount of spam sent to Gmail, this message has been 5.7.1 blocked. Please visit 5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant 5.7.1 and review RFC 5322 specifications for more information. p18si54042ood.13 - gsmtp
Code to send email: (Via postfix using mailgun)
$lead_email = BCC_EMAIL;
$cc_email = LEAD_CC_NOTIFICATION_EMAIL;
$message = <<<MSG
<p>Hi PHP POS Admin,</p>
<p>You have received a TRIAL CONVERSION from the customer below: </p>
<ul>
<li>Company: $data[company]</li>
<li>Name: $data[name]</li>
<li>E-Mail: $data[email]</li>
<li>Phone: $data[phone]</li>
<li>Provider: $data[payment_provider]</li>
<li>Address: <strong>$data[country]</strong> $data[address_1] $data[address_2] $data[city] $data[state], $data[zip]</li>
<li>IP Address: $data[ip_address]</li>
<li>IP Address Location: $data[ip_geo]</li>
</ul>
Regards<br>
</p>
MSG;
$from = $lead_email;
$subject = 'SUBJECT';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: ".$from . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
mail($lead_email, $subject, $message, $headers);
Raw MIME:
Received: by REDACTED (Postfix, from userid 48)
id 91F58812D2; Tue, 19 May 2020 17:51:59 +0000 (UTC)
To: REDACTED
Subject: REDACTED
X-PHP-Originating-Script: 500: REDACTED
MIME-Version: 1.0
From: example#example.com
Content-type: text/html; charset=UTF-8
Message-Id: < REDACTED >
Date: Tue, 19 May 2020 17:51:59 +0000 (UTC)
<p>Hi PHP POS Admin,</p>
<p>You have received a TRIAL CONVERSION from the customer below: </p>
<ul>
<li>Company: REDACTED</li>
<li>Name: REDACTED </li>
<li>E-Mail: REDACTED </li>
<li>Phone: REDACTED </li>
<li>Provider: braintree</li>
<li>Address: <strong> REDACTED </strong> , REDACTED </li>
<li>IP Address: REDACTED </li>
<li>IP Address Location: , , </li>
</ul>
Regards,<br>
PHP Point Of Sale Team
</p>
I ended up using phpmailer as this manages all the headers. So far it has worked

PHP MySql fetch json no content

I have problem fetching my result from db and convert to json. In my API call, It gives me empty content(total blank) of returned body with status 200.
This is my code:
$weekAndYear = $year."/".$week; // incoming params as e.g "2016/19"
$stmt = $this->db->prepare("SELECT r.*, p.code FROM report r, product p WHERE "
. "r.pid=p.pid AND r.product=:productCode "
. "AND r.status='Published' AND r.pid=25 AND r.week=:weekAndYear");
$stmt->bindparam(":productCode", $productCode);
$stmt->bindparam(":weekAndYear", $weekAndYear);
$stmt->execute();
while($price=$stmt->fetch(PDO::FETCH_ASSOC)) {
//echo $price;
$arr_price[] = $price;
}
$data['priceReport'] = $arr_price;
//echo $weekAndYear;
$data['status'] = "OK";
return json_encode($data);
When I tested the query in my phpmyadmin mysql server and it works fine.
On my php side, different $weekAndYear params will have some working well and some are not. Anything wrong on array part?
My API response headers:
Cache-Control →no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Connection →Keep-Alive
Content-Length →0
Content-Type →application/json
Date →Thu, 05 May 2016 06:49:28 GMT
Expires →Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive →timeout=5, max=100
Pragma →no-cache
Server →Apache/2.4.18 (Unix) LibreSSL/2.2.6 PHP/5.5.31
X-Powered-By →PHP/5.5.31
I've been scratching my head for few days and now I just have few hairs left.
Please help. Thank you.
I'm assuming (maybe wrongly) that your code snippet isn't a function.
Change the last line from return to echo as follows:
echo json_encode($data);
Unless the first code snippet is a function, you need to use json_encode not a return statement.
What happens is that Fetch can fetch any type of content, even HTML. What PHP does is it generates content writes it to a file and sends it to the browser. When you generate HTML with PHP you do not return it, you echo it to the page.
The same thing happens with AJAX. You use PHP to write data to a file and serve it.
So replace this:
return json_encode($data);
with this:
echo json_encode($data);

Can't send BCC emails through Mandrill (via Laravel)

I am unable to send emails to users through the Mandrill plugin in Laravel using BCC. I can send emails "to" the addresses, as follows:
Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->to($email);
}
$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});
This works just fine. However, if I try to BCC the same users:
Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->bcc($email);
}
$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});
Nothing happens. Mandrill doesn't even acknowledge that the request came in. Any ideas why this isn't working? If it helps, here are my raw email headers:
Message-ID: <688aa904847640c9ff694521ccb85ee5#nudge-api.app>
Date: Thu, 07 Aug 2014 11:15:35 -0400
Subject: Coach McTest would like to be your Coach on Nudge!
From: Nudge Info <info#nudgeyourself.com>
Bcc: Chris Garson <chris#nudgeyourself.com>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I can confirm that sending emails to Bcc users doesn't really work as expected in Mandrill.
The easiest way to send what you want (single email to multiple addresses, with each addressee only seeing their own name in the delivery list), is to set the X-MC-PreserveRecipients header to false and then just send the email using the To field rather than Bcc.
This will send the email as if it were sent to each recipient individually, rather than as a group email - nobody will know who else was sent the email.
Here's how to do it in Laravel using your example:
Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
foreach ($emails as $email) {
$message->to($email);
}
$message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-PreserveRecipients', 'false');
});
Note that I'm using $message->to() to address the email and then adding the X-MC-PreserveRecipients header which is set to false.
I worked for me both CC and BCC way.
Ref document: https://mandrill.zendesk.com/hc/en-us/articles/205582117-Using-SMTP-Headers-to-customize-your-messages
Search keyword: X-MC-PreserveRecipients
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-PreserveRecipients', true);
Using the X-MC-BccAddress should do the job. You can only use one bcc address though.
See https://mandrill.zendesk.com/hc/en-us/articles/205582117-Using-SMTP-Headers-to-customize-your-messages

HTML Emails Displaying odd in some clients

I'm using PHP to generate a fancy HTML email to send to visitors, but for some reason certain visitors are saying the HTML isn't working for them (seeing RAW HTML rather than pretty email).
I haven't narrowed it down to a certain client, but having talked to them they say they can receive other HTML emails so it's something I'm doing wrong...
My PHP code is as follows
$to = 'jm391#le.ac.uk';
$subject = 'Daily Update - New Bikes Matching Your Alerts';
$headers = "From: john#findthatbike.co.uk\r\n";
$headers .= "Reply-To: john#findthatbike.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (mail($to, $subject, $message, $headers)) {
echo 'Your message has been sent<br/>';
} else {
echo 'There was a problem sending the email.<br/>';
}
And my $message variable is loaded with the below links HTML source
http://www.findthatbike.co.uk/sampleemail.html
My customer forwarded a non working email to me and the forwarded chunk look like the below, I'm told he gets HTML emails from others so really not sure what to try...
From: john#findthatbike.co.uk [mailto:john#findthatbike.co.uk]
Sent: 05 April 2013 08:35
To: XXXXX XXXXX
Subject: Daily Update - New Bikes Matching Your Alerts
Reply-To: john#findthatbike.co.uk
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
Message-Id: <20130405073022.8597D9CF79D#MY SERVER ADDRESS>
Date: Fri, 5 Apr 2013 08:30:22 +0100 (BST)
X-invURIBL-Scan: Scanned by invURIBL 3.1.1 on 05/04/2013 08:34:17
X-invURIBL-Weight: 0
X-invURIBL-Range: CLEAN
X-Declude-Sender: MY SERVER NAME [MY SERVER IP]
X-Declude-Spoolname: 72086847.eml
X-Declude-RefID:
X-MessageStream-Note: Scanned by MessageStream (www.messagestream.com).
X-MessageStream-Scan: Score [0] at 08:34:29 on 05 Apr 2013
X-MessageStream-Tests: Whitelisted
X-Country-Chain: UNITED KINGDOM->destination
<html>
<body style="background:url('http://findthatbike.co.uk/images/bg3.jpg') repeat fixed 0 0 #EEEEEE; padding-top: 10px; padding-bottom: 10px;">

Categories