通过联系表单将邮件发送到电子邮件ID

时间:2014-10-27 05:25:48

标签: php email

我在网站上有一个联系表格,用户可以向网站所有者发送消息。联系表格是

<form class="form" id="form1" action="send_form_email.php" method="post">
    <p class="name">
        <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
    </p>

    <p class="phone">
        <input name="phone" type="text" class="validate[required,custom[email]] feedback-input" id="phone" placeholder="Phone Number" />
    </p>

    <p class="email">
        <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
    </p>

    <p class="businessname">
        <input name="business_name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Business Name" id="name" />
    </p>

    <p class="text">
        <textarea name="comment" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Comment"></textarea>
    </p>

    <div class="submit">
        <input type="submit" name="submit" value="Submit!"  id="button-blue"/>
        <div class="ease"></div>
    </div>
</form>

send_form_email.php的编码是:

<?php 
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$business_name = $_POST['business_name'];
$comment = $_POST['comment'];

$from = 'From: website.com'; //url of contact form or website
$to = 'user@gmail.com'; //my email id
$subject = 'Customer Inquiry';
$body = "From: $name\n Phone: $phone\n E-Mail: $email\n Business Name: $business_name\n Message:\n $message";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = 'From: from@example.com' . "\r\n" .
'Reply-To: reply@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
header( "Location: index.html" );
?>

问题是它在第6行显示错误(即$comment = $_POST['comment'];)说Parse错误:语法错误,/ nfs /c11 / h01 / mnt / 193678 / domain / website /中的意外T_STRING第6行的html / admin / send_form_email.php

EDIT: 1

我已经删除了由于某些服务器问题导致的错误..但现在错误是当邮件发送给管理员时,邮件中的邮件是空白的,我希望收到姓名,电子邮件,phoneno ,邮件中的业务和评论

1 个答案:

答案 0 :(得分:1)

将您的$body更改为此消息

$message = "From: $name\n Phone: $phone\n E-Mail: $email\n Business Name: $business_name\n Message:\n ";