Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

When sending a email in PHP program, How do I insert a image?

Posted on 2015-01-09
5
Medium Priority
?
322 Views
Last Modified: 2015-01-16
This is a sample of the coding:
-----------------------------------------------------------------------------------------------------------
$message = "";
                if(isset($_SESSION["NewAccountCreated"])) {
                    $message = "Hello ".$order->Billing->Name.",\n".
                        "Thank you for ordering and registering an account at www.ZZZZZZZ.com. ".
                        "We have received your order. Should you need to make changes to your order, ".
                        "please call us at XXX.YYY.6457, during our normal business hours (see below). ".
                        "We are glad to help you. Please remember, orders placed by 12 noon, pacific time, ".
                        "ship the same business day. Below is your order confirmation number, please ".
                        "keep a copy of it should you need to reference your order.\n\n".
                        "Order Confirmation #: ".$salesOrderNumber."\n\n".
                        "Account #: ".$account->CustomerNumber."\n\n".
                        "Thank you!\n-The ZZZZZZZ Team";
                } //end if
                else if(isset($_SESSION["LoginEmail"])) {
                    $message = "Order Confirmation.\n\n".
                        "Thank you for your recent order with ZZZZZZZ. ".
                        "Whats Next? Once your order ships an Invoice and tracking number".
                        "             will be emailed to you.".
                        "We have received your order. Should you need to make changes to your ".
                        "order, please call us at XXX.YYY.6457, during our normal business hours ".
                        "(see below). We are glad to help you. Please remember, orders placed by ".
                        "12 noon, pacific time, ship the same business day. Below is your order ".
                        "confirmation number; please keep it handy should you need to reference your order.\n\n".
                        "\t\t\t Order Confirmation #: ".$salesOrderNumber."\n\n".
                        "\t\t\t Account #: ".$account->CustomerNumber."\n\n".
                        "\t\t\t Customer Name - ".$order->Billing->Name.".\n\n".
                        "Thank you!\n- The ZZZZZZZZ Team";
                } //end else
------------------------------------------------------------------------------------------------------------------
Here is the result:

Order Confirmation.

Thank you for your recent order with ZZZZZZZ. Whats Next? Once your order ships an Invoice and tracking number             will be emailed to you.We have received your order. Should you need to make changes to your order, please call us at XXX.YYY.6457, during our normal business hours (see below). We are glad to help you. Please remember, orders placed by 12 noon, pacific time, ship the same business day. Below is your order confirmation number; please keep it handy should you need to reference your order.

                   Order Confirmation #: I149705

                   Account #: 0000007

Customer Name - TEST - TEST - IT - TEST.

Thank you!
- The ZZZZZZZZ Team

----------------------------------------------------------------------------------------------------
I like to have our Company logo in the Email and a product image?

Can I do something like that?
0
Comment
Question by:Scott Johnston
  • 4
5 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 40541358
Yes but you can't include them in the email.  you're better off referencing those images from your website and show them in your email using html img tags
e.g.
<img src='domain.com/path/to/images/logo.jpg>
<img src='domain.com/path/to/products/xyz/xyz.jpg>
0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 2000 total points
ID: 40541359
you should also set the email to be HTML as well as plain text for the email client to choose how it wants to read it.  Most email clients will allow HTML but will require the user to "show pictures".  As a fallback you should include a text based version as well with the basics of the order confirmation.

As a reference this article explains the differences with how to include images in emails.  As you can see, the best way is to reference them via a CDN (which is just your website)
https://sendgrid.com/blog/embedding-images-emails-facts/
0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 2000 total points
ID: 40541365
The below PHP code will set both the HTML and text based versions for you.

$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->CharSet = "text/html; charset=UTF-8;";
...
$mail->Body =  $htmlMessage;
$mail->AltBody  =  $textMessage;
...
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 40541372
Here is a good basic article on sending HTML emails: http://css-tricks.com/sending-nice-html-email-with-php/

Just be sure to include a text based version as previously described by using the AltBody attribute of the mail object.
0
 

Author Closing Comment

by:Scott Johnston
ID: 40554098
Rob, thank you for the guide line on this.  It was very helpfull.!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question