【发布时间】:2014-01-30 00:54:26
【问题描述】:
我使用 php 5.3.13 、pear mail 和 google captcha (recaptcha) 创建了一个简单的“联系我们”表单。
有一个电子邮件字段、一个主题字段和一个 cmets 字段。用户还解决了验证码,然后他可以按“发送”。
这在我的笔记本电脑上本地运行良好,而不是在我安装站点的服务器上运行。它的代码完全相同。
我使用一个简单的 gmail 作为smtp 服务器,我的大学拥有的服务器。有两个文件,contact,包含表单和contactsend,获取数据并发送它们。他们来了
联系
<?php
require_once('recaptchalib.php');
include_once('header.php');
?>
<form method="post" action="contactsend.php">
e-mail :<br>
<input name="mail" id="mail" type="email" class="textformfront" placeholder="e-mail" required onFocus="document.getElementById('mes').innerHTML='';" >
<br>
subject:<br>
<input name="subj" id="subj" type="text" class="textformfront" placeholder="subject" required onFocus="document.getElementById('mes').innerHTML='';">
<br>
comments:<br>
<textarea name="comment" id="comment" class="textformfront" rows="24" cols="50" placeholder="comments" required onFocus="document.getElementById('mes').innerHTML='';"></textarea>
<br>
<p>please solve the captcha and hit Send. <br>
</p>
<br>
<?php
$publickey = "0000000000000000" ; // captcha key
echo recaptcha_get_html($publickey); ?>
<br>
<input type="submit" class="formButtonMap" value="Send"/>
</form>
<br>
<?php
if ($_GET['ce']) {
echo '<div id="mes"> an error occured</div>';
}
if ($_GET['co']) {
echo '<div id="mes">your message send</div>';
}
if ($_GET['cc']) {
echo '<div id="mes">wrong captcha. try again</div>';
}
?>
<?php
include_once('footer.php');
?>
联系发送
<?php
require_once('recaptchalib.php');
include('Mail.php');
//get data from form
$maila = $_POST['mail'];
$comment = $_POST['comment'];
$subj = $_POST['subj'];
$privatekey = "6Lf1a-ESAAAAAMjQPerOTppYKwDH6oF7o6MM50Jr";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
//if wrong captcha send back
if (!$resp->is_valid) {header('Location:contact.php?cc=1'); exit();}
//else send mail
else {
$email = "mymail@gmail.com";
$message = $comment;
$from = $maila;
$to = "mymail@gmail.com";
$subject = $subj;
$body = $message;
$host = "ssl://smtp.server.address";
$username = "aaaa";
$password = "00000";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => "text/plain; charset=\"UTF-8\"",
'Content-Transfer-Encoding' => "8bit"
);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password,
'port' => '465'
)
);
$mail = $smtp->send($to, $headers, $body);
//if there is an error while sendig mail, send back
if (PEAR::isError($mail)) {header('Location:contact.php?ce=1'); exit();}
//if success while sending mail, send back
else {header('Location:contact.php?co=1'); exit();}
}
?>
当我以简单用户身份访问该站点时,我收到 HTTP 500 错误。我不知道如何解决这个问题。有什么建议?
谢谢
编辑
在我放置网站的服务器上,我安装了 PEAR 和 Mail。是 windows server 2012 r2 并且有 php 5.3.13。现在,一位朋友告诉我编辑php.ini,这样就可以了。我编辑这个
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = ssl://smtp.uwg.gr
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = culturalmapupatra@gmail.com
还有这个
;***** Added by go-pear
include_path=".;C:\Program Files (x86)\PHP\PEAR\Mail"
仍然没有运气。我错过了什么?
谢谢一百万
【问题讨论】:
-
检查你的后端。如果您尝试使用学校的 SMTP,他们可能已经阻止了。您可以使用 php 邮件作为后端,这样可以绕过学校的 SMTP。请参阅此处的注释 [PEAR] (pear.php.net/manual/en/package.mail.mail.factory.php)。你可以试试
code$mail_object =& Mail::factory('mail', '-fbounce@domain.com') ;code -
PEAR 也可以在学校服务器上使用吗?
-
@cilosis 好问题。我不确定,但我想是的。正如我所说,我的代码在我的笔记本电脑(本地)上运行良好,并且因为我将它传输到服务器,所以没有。所以,由于我的代码正在运行,我猜 PEAR 是可用的。
-
在您的笔记本电脑上工作表明您的本地环境拥有您需要的一切。这不意味着服务器可以。
-
错误是什么? 500 是 HTTP 状态码。这不是错误。 Enable PHP error reporting 或查看日志文件。否则我们无能为力