使用php发送电子邮件

时间:2013-12-10 01:01:27

标签: php html email

我正在尝试从我的网站表单发送电子邮件,但它一直显示此错误 解析错误:语法错误,第5行/home/u892828859/public_html/message.php中的意外T_VARIABLE

这是我的php:

<? php

    // subject and email variables

        $emailSubject = 'message from friend';
        $webMaster    = 'myemail@gmail.com';

    // gathering data variables 

        $emailField = $_POST['email'];
        $subjectField = $_POST['subject'];
        $messageField = $_POST['message'];

        $body = <<<EOD
<br><hr><br>
Email : $email <br>
Subject: $subject <br>
Message : $message <br>
EOD;

    $headers = "from : $email\r\n";
    $headers .="Content=type: text/html\r\n"; /*to let php code to run the html tag as html and rest text*/
    $success = mail($webMaster, $emailSubject, $body, $headers);

    // Result rendered as HTML 

    $theResults = <<<EOD
<html lang="en">

    <head>
        <title><Contact></title>
        <meta charset="utf-8" />
        <link rel ="stylesheet" href="stylec.css" type="text/css" />
        <meta name ="viewport" content="width=device-width, initial-scale=1.0"/>    
    </head>
    <body>
        <p>Your message has been sent </p>
        <a href ="contact.html"  > GO back</a>
</html>
EOD;

echo "$theResults";
?>

and here is my form from my website 


                    <form action="message.php" method="post">
                        Email : </br><input type ="text" name="email"></br>
                        Subject :</br><input type ="text" name ="subject"></br>
                        Message : <br>
                        <textarea rows="10" name ="message" ></textarea>
                        </br>
                        <input type ="submit" value="submit">
                    </form>

任何人都可以告诉我,我做错了什么。 感谢

2 个答案:

答案 0 :(得分:1)

这很简单......

<? php

<?php

答案 1 :(得分:0)

在你的第一行中,它们之间有空格?和PHP。尝试删除空间。