Solved

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

Posted on 2015-01-09
5
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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 43

Assisted Solution

by:Rob
Rob 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 43

Accepted Solution

by:
Rob 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

634 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