我是 PHP 新手,但是,我有一个简单的联系表格发送到我的电子邮件。$message
除了变量未显示外,一切都按预期工作。
php 正在处理请求并将网站查看器发送到感谢页面,查看器也收到确认电子邮件,并且我收到了包含除$message
数据之外的所有请求变量的电子邮件。
$totalmessage
由于mail()
功能限制,变量被合并到。
正如我所说,我是 php 新手,但感谢您的帮助。
PHP代码:
<?php
$to = "me@mywebsite.com";
$subject = "Inquiry";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
if (isset($_POST['interest']) && $_POST['interest']!= 'none'){
if (is_array($_POST['interest'])){
$interest = implode(" ", $_POST['interest']); // format your array for use
} else {
$interest = $_POST['interest']; // no array -> print single value
}
}
$method = $_REQUEST['method' ] ;
$message = $_GET['message'] ;
$totalmessage = "
Name: $name \n
Email: $email \n
Phone: $phone \n
Interest: $interest \n
Method: $method \n
Message: $message \n ";
$headers = "From: $email";
$sent = mail($to, $subject, $totalmessage, $headers);
if($sent)
header( "Location: /thankyou.html" );
else
print "We encountered an error sending your mail";
?>
HTML 代码:
<div class="row">
<br><label for="message"> Message:</label><br/>
<textarea name="message" rows="20" cols="20" id="message"></textarea>
</div>
电子邮件输出:
Name: bob
Email: bob@gmail.com
Phone: 123-456-7890
Interest: research
Method: email
Message: <===should have message text