Jump to content

[SOLVED] Displaying content in a table format when mailed from a html form using php code


GrizzlyBear

Recommended Posts

Hi

 

I have attached an image of what I want to do below.

 

Basically I have created a form and executing the form using PHP coding. But I need help in being able to specify the format the content inserted into the form will be display in the received email.

 

Thanks

 

PS: Here is the html form coding for the above mailer...

 

<td width="300" class="style1">

                      <input class="formstyle1" id="name2" maxlength="50" size="40"

            name="Name" />                    </td>

                    </tr>

                  <tr>

                    <td width="200" class="style1"> </td>

                    <td width="300" class="style1"> </td>

                  </tr>

                  <tr>

                    <td width="200" height="20" class="style1"><strong>Surname</strong></td>

                    <td width="300" class="style1">

                      <input class="formstyle1" id="surname2" maxlength="11"

            size="40" name="Surname" />                    </td>

                  </tr>

                  <tr>

                    <td width="200" class="style1"> </td>

                    <td width="300" class="style1"> </td>

                  </tr>

                  <tr>

                    <td width="200" height="20" class="style1"><strong>Telephone</strong></td>

                    <td width="300" class="style1">

                      <input class="formstyle1" id="telephone2" maxlength="50"

            size="40" name="Telephone" />                    </td>

                  </tr>

                  <tr>

                    <td width="200" class="style1"> </td>

                    <td width="300" class="style1"> </td>

                  </tr>

                  <tr>

                    <td width="200" height="20" class="style1"><strong>E-mail</strong></td>

                    <td width="300" class="style1">

                      <input class="formstyle1" id="email2" maxlength="50"

            size="40" name="Email" />                    </td>

                  </tr>

                  <tr>

                    <td width="200" class="style1"> </td>

                    <td width="300" class="style1"> </td>

                  </tr>

                  <tr>

                    <td width="200" height="20" class="style1"><strong>Enquiry</strong></td>

                    <td width="300" class="style1">

                      <label>

                      <textarea name="Enquiry" cols="41" rows="5" class="style1" id="enquiry2"></textarea>

                      </label>                    </td>

 

[attachment deleted by admin]

This isn't a failsafe method. A lot of people have HTML formatting switched off for their e-mails, in which case if you were to send a HTML formatted e-mail they would get thoroughly confused. You should provide an option for your users to select which format the e-mail should be in. And in which case, if they make a mistake it's down to them. And you'll then be able to determine which format the e-mail should be sent in, either plain text or HTML.

 

But back to your original question:

<?php

$to = '[email protected]';

$message = '<html><head><title>HTML E-mail!</title></head><body>This is an HTML e-mail!</body></html>';

$subject = 'HTML E-mail!';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]';

mail($to, $subject, $message, $headers);

?>

Thanks Wolphie, that was exactly what i was looking for.

 

I just have one more q... how do i get the $info command to work in table in the script below?

 

thanks hey..

 

<?php

 

$to = '[email protected]';

$email = $_REQUEST['email'];

$info = $_REQUEST['message'];

 

$message = '

<html>

<head>

<title>HTML E-mail!</title>

</head>

<body>

<table border="1">

<tr>

<td>$info</td>

<td>This is an HTML e-mail!</td>

<td>This is an HTML e-mail!</td>

</tr>

</table>

</body>

</html>';

 

$subject = 'HTML E-mail!';

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: $email';

 

mail($to, $subject, $message, $headers);

 

?>

<?php

$to = '[email protected]';
$email = $_POST['email'];
$info = $_POST['message']; // this should be the same as the name on the form element

$message = <<<MESSAGE
<html>
  <head>
    <title>HTML E-mail!</title>
  </head>
  <body>
    <table border="1">
      <tr>
        <td>$info</td>
        <td>This is an HTML e-mail!</td>
        <td>This is an HTML e-mail!</td>
      </tr>
    </table>
  </body>
</html>
MESSAGE;

$subject = 'HTML E-mail!';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $email;

mail($to, $subject, $message, $headers);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.