1

I am trying to sending an HTML email upon an order submission , hence at first I read last inserted row in database

if(isset($_POST['submit'])) {

    $sql2 = "SELECT * FROM `$db`.`pre_order` ORDER BY id DESC LIMIT 0,1;";
    $result = mysql_query($sql2, $dbcon);
    $row = mysql_fetch_array($result);
    $id= $row['id'];
    $name=$row['name'];
    $address=$row['delivery_location'];
    $mobile =$row['mobile'];
    $email= $row['email'];
    $to = $email;
    $from = "[email protected]"; 
    $subject = "Thanks You message";    

    $message = '

                <html>
                    <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <title>Sundori Honey</title>
                        <link rel="stylesheet" href="css/table.css" type="text/css">
                    </head>
                    <body style="width:600px;">
                        <div class="begining">  
                            <p>
                                Dear <span> <?php echo $name?></span> <br/>

                Thank you for your booking. We are pleased to confirm detail as follows:

                            </p>
                        </div>
                        <table border="1" style="width:80% ;margin: auto;">

                            <tr>
                                <td>Confirmation Number: </td>
                                <td> <?php echo $id;?></td>
                            </tr>
                            <tr>
                                <td>Client’s Name & Contact No:</td>
                                <td><?php echo $name .' and ' .$mobile;?></td>
                            </tr><tr>
                                <td> Contact Address:</td>
                                <td><?php echo $address;?></td>
                            </tr>




                        </table>
                            <div class="begining">  
                            <p>

    Thanks
                            Sincerely,<br/><br/>

                Johm<br/><br/>
                Manager – Marketing & Sales<br/>
                </p>
                        </div>
                    </body>

                </html>
                '; /*---end of HTML msg--*/


    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
    mail($to, $subject, $message, $headers); 

Upon form submission , I do get a msg , but the problem is , it only show something like this

The mail doesn't show any value which I have read from database and It show only two rows of the table , Even it doesn't show the footer text which is located below table .

2
  • The sql query is right , I have printed out it in HTML page . It works exactly as I want to . Commented Feb 12, 2014 at 8:06
  • Also, for large portion of code, consider heredoc. Commented Feb 12, 2014 at 8:06

6 Answers 6

3

The values of variables will not be parsed under single quotes !

You have this $message variable ..

 $message = '....... your content .....';

Enclose that under double quotes like this..

$message = " ..... your content ......';

Otherwise , you could make use a HEREDOC syntax.

The HEREDOC Syntax for your $message variable.

$message=<<<HTMLMAIL

.... your content..........
// more content....
HTMLMAIL;

Paste all the content inside your $message variable and put it under the HEREDOC

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I didn't know about heredoc.
0

-Does not use the php tags in php

-You must concatenate "name" and "adresse" with the point (.)

Like this

  <tr>
       <td>Client’s Name & Contact No:</td>
         <td>'.$name .' and ' .$mobile.'</td>
       </tr><tr>
       <td> Contact Address:</td>
       <td>'.$address.'</td>
  </tr>

Comments

0

Try this:

$message = '

        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title>Sundori Honey</title>
                <link rel="stylesheet" href="css/table.css" type="text/css">
            </head>
            <body style="width:600px;">
                <div class="begining">  
                    <p>
                        Dear <span>' . $name . '</span> <br/>

        Thank you for your booking. We are pleased to confirm detail as follows:

                    </p>
                </div>
                <table border="1" style="width:80% ;margin: auto;">

                    <tr>
                        <td>Confirmation Number: </td>
                        <td>' . $id . '</td>
                    </tr>
                    <tr>
                        <td>Client’s Name & Contact No:</td>
                        <td>' . $name .' and ' . $mobile . '</td>
                    </tr><tr>
                        <td> Contact Address:</td>
                        <td>' . $address . '</td>
                    </tr>




                </table>
                    <div class="begining">  
                    <p>Thanks
                    Sincerely,<br/><br/>

        Johm<br/><br/>
        Manager – Marketing & Sales<br/>
        </p>
                </div>
            </body>

        </html>
        ';

Comments

0

Replace your $message value.

$message = '

                <html>
                    <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        <title>Sundori Honey</title>
                        <link rel="stylesheet" href="css/table.css" type="text/css">
                    </head>
                    <body style="width:600px;">
                        <div class="begining">  
                            <p>
                                Dear <span>'.$name.'</span> <br/>

                Thank you for your booking. We are pleased to confirm detail as follows:

                            </p>
                        </div>
                        <table border="1" style="width:80% ;margin: auto;">

                            <tr>
                                <td>Confirmation Number: </td>
                                <td>'. $id.'</td>
                            </tr>
                            <tr>
                                <td>Client’s Name & Contact No:</td>
                                <td>'. $name .' and ' .$mobile .'</td>
                            </tr><tr>
                                <td> Contact Address:</td>
                                <td>'. $address .'</td>
                            </tr>




                        </table>
                            <div class="begining">  
                            <p>

    Thanks
                            Sincerely,<br/><br/>

                Johm<br/><br/>
                Manager – Marketing & Sales<br/>
                </p>
                        </div>
                    </body>

                </html>
                '; 

Comments

0

Use this code for $message variable

$message = '<html>
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title>Sundori Honey</title>
                    <link rel="stylesheet" href="css/table.css" type="text/css">
                </head>
                <body style="width:600px;">
                    <div class="begining">  
                        <p>
                            Dear <span>'.$name.'</span> <br/>

            Thank you for your booking. We are pleased to confirm detail as follows:

                        </p>
                    </div>
                    <table border="1" style="width:80% ;margin: auto;">

                        <tr>
                            <td>Confirmation Number: </td>
                            <td>'.$id.'</td>
                        </tr>
                        <tr>
                            <td>Client’s Name & Contact No:</td>
                            <td>'.$name .' and ' .$mobile.'</td>
                        </tr><tr>
                            <td> Contact Address:</td>
                            <td>'.$address.'</td>
                        </tr>




                    </table>
                        <div class="begining">  
                        <p>

Thanks
                        Sincerely,<br/><br/>

            Johm<br/><br/>
            Manager – Marketing & Sales<br/>
            </p>
                    </div>
                </body>

            </html>'; 

Comments

0

You have lots of error in you code. You have used <?php echo ?> tags at unwanted places

you dont want to specify inside php again. You are just storing those html content as a string. so remove it from $message like

change this

Dear <span> <?php echo $name?></span> <br/>

to

Dear <span>  $name</span> <br/>

also while using doubles dont forget change the quotes in html attributes to single quotes

so change whole $message to this

$message = "

                <html>
                    <head>
                        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
                        <title>Sundori Honey</title>
                        <link rel='stylesheet' href='css/table.css' type='text/css'>
                    </head>
                    <body style='width:600px;'>
                        <div class='begining'>  
                            <p>
                                Dear <span>$name</span> <br/>

                Thank you for your booking. We are pleased to confirm detail as follows:

                            </p>
                        </div>
                        <table border='1' style='width:80% ;margin: auto;'>

                            <tr>
                                <td>Confirmation Number: </td>
                                <td> $id</td>
                            </tr>
                            <tr>
                                <td>Client’s Name & Contact No:</td>
                                <td> $name  and $mobile </td>
                            </tr><tr>
                                <td> Contact Address:</td>
                                <td> $address </td>
                            </tr>




                        </table>
                            <div class='begining'>  
                            <p>

    Thanks
                            Sincerely,<br/><br/>

                Johm<br/><br/>
                Manager – Marketing & Sales<br/>
                </p>
                        </div>
                    </body>

                </html>
                "; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.