Jump to content

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


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 = 'example@domain.com';

$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: anotherexample@domain.com';

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 = 'test@domain.co.za';

$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 = 'test@domain.co.za';
$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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.