user289040
user289040

Reputation: 409

PHP email formatted content

I am creating an email form for my website which will allow a user to create an email and appear to be sent from any email address they wish. i.e. [email protected].

The form works fine, until I made one small change. I previously allowed the user to submit the content of the email but was finding difficulty in formatting the content (i.e. making areas bold, using a table etc).

(Form code now)

<html>
<body>
<form method="GET" action="send.php">

<p>To: <input type="text" name="to" /></p>
<p>From-Name: <input type="text" name="name" /></p>
<p>From-Email: <input type="text" name="from" /></p>
<p>Subject: <input type="text" name="subject" /></p>


<input type="submit" value="Send E-Mail" ></p>
</form>
</body>
</html>

So I thought it would be easier to submit the content myself in my 'send.php' code that actually sends the email message. This is displayed below:

 <html>
    <body>
    <?php
    $to =$_REQUEST['to'];
    $subject = $_REQUEST['subject'];
    $name =$_REQUEST['name'];
    $from = $_REQUEST['from'];
    $content = ?><font face="arial"><b>Your question has been received/b>

    Your booking has been confirmed with the supplier.
    Please visit the <a href="questionstory.co.uk"> Question Portal</a> for more information.

    <table>
    <tr>
    <td>Question subject</td>
    <td> Room</td>
    </tr>
    <tr>
    <td>Traveller</td>
    <td>Maria Smith</td>
    </tr>
    <td>Requester</td>
    <td>Tony Smith</td>
    </tr>
    </table>

    <br/>


     </font>

    <?
    $header="From: $from"."<$sender_email>\r\n";
    mail($to,$subject,$content,$header);
    echo 'sent successfully';

    ?>
    </body>
    </html>

However, when I click submit, my server finds an error. I can only presume it is because of my HTML element as this error was not occurring previously without it.

Can anyone advise how I can fix this / if you can suggest an easier way for me to format the email content I would like?

Many thanks

Upvotes: 0

Views: 59

Answers (2)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

Try this

<?php
    $to = $_REQUEST['to'];
    $subject = $_REQUEST['subject'];
    $name = $_REQUEST['name'];
    $from = $_REQUEST['from'];
    $content =
        '<span style="font-family: arial"><b>Your question has been received</b>
            <br>
            Your booking has been confirmed with the supplier.
            Please visit the <a href="questionstory.co.uk"> Question Portal</a> for more information.

            <table>
                <tr>
                    <td>Question subject</td>
                    <td> Room</td>
                </tr>
                <tr>
                    <td>Traveller</td>
                    <td>Maria Smith</td>
                </tr>
                <td>Requester</td>
                <td>Tony Smith</td>
                </tr>
            </table>

            <br/>
            </span>';

    $header = "From:".$from;
    $result = mail($to,$subject,$content,$header);
    if(isset($result))
    {
        echo 'sent successfully';
    }
    else
    {
        echo 'Failed';
    }


?>

Note: <font> tag not supported in HTML5

EDIT 01

Include this lines too

$header .= 'MIME-Version: 1.0';
$header .= 'Content-Type: text/html; charset="ISO-8859-1';

Upvotes: 1

Crunch Much
Crunch Much

Reputation: 1527

Set your content value to

$content = ''

Since your $content is undefined that is why you are getting error.

Hope this will fix your issue.

Upvotes: 1

Related Questions