Solved

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

Posted on 2015-01-09
5
282 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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 500 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 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 500 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 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Cordova Camera plugin fails 2 21
showing numeric numbers 2 11
two tables one button 11 19
Simple Angular 2 login page 4 6
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now