Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

810 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