简体   繁体   English

PHP电子邮件格式的内容

[英]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. 我正在为我的网站创建一个电子邮件表单,该表单将允许用户创建电子邮件并似乎从他们希望的任何电子邮件地址发送出去。 ie davidcameron@downingstreet.com. 即davidcameron@downingstreet.com。

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 (ie 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. 因此,我认为自己在实际发送电子邮件的“ send.php”代码中提交内容会更容易。 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. 我只能认为这是因为我的HTML元素,因为以前没有它就不会发生此错误。

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 非常感谢

Set your content value to 将您的内容值设置为

$content = ''

Since your $content is undefined that is why you are getting error. 由于您的$ content未定义,这就是为什么您会出错。

Hope this will fix your issue. 希望这能解决您的问题。

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 注意: HTML5不支持 <font>标记

EDIT 01 编辑01

Include this lines too 也包括此行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM