I use php 5.3.13 ,pear mail and google captcha (recaptcha) to create a simple "contact us" form.
我使用php 5.3.13、pear邮件和谷歌captcha (recaptcha)创建一个简单的“联系我们”表单。
There is an email field, a subject field and a comments field. User has also solve the captcha and then he can press "Send".
有一个电子邮件字段,一个主题字段和一个评论字段。用户也解决了captcha,然后他可以按“发送”。
This works fine locally n my laptop, not on the server I installed the site. Its the exact same code.
这在我的笔记本电脑上运行得很好,而不是在我安装网站的服务器上。完全一样的代码。
I use a simple gmail and as smtp
server, the server my university has. There are two files, contact
, that contains the form and contactsend
that gets the data and sends them. Here they are
我使用一个简单的gmail作为smtp服务器,这是我所在大学的服务器。有两个文件,contact,其中包含获取数据并发送数据的表单和contactsend。他们在这里
contact
联系
<?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');
?>
contactsend
contactsend
<?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();}
}
?>
When I access the site as a simple user I get HTTP 500 error. I dont know how to fix this. Any suggestions?
当我作为一个简单的用户访问站点时,我得到了HTTP 500错误。我不知道怎么解决这个问题。有什么建议吗?
Thanks
谢谢
EDIT
编辑
On the server I put my site, I installed PEAR and Mail. Is a windows server 2012 r2 and has php 5.3.13. Now, a friend told me to edit the php.ini
so this can work. I edit this
在我放置站点的服务器上,我安装了PEAR和Mail。是windows server 2012 r2, php 5.3.13。现在,一个朋友让我编辑php。所以这个可以用。我编辑这个
[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
and this
这
;***** Added by go-pear
include_path=".;C:\Program Files (x86)\PHP\PEAR\Mail"
and still no luck. What am I missing?
和仍然没有运气。我缺少什么?
Thanks a million
谢谢一百万
1 个解决方案
#1
0
Try to use TLS instead of ssl also play a bit the port 587. I have noticed that google has these problems. Check their settings here: https://support.google.com/mail/troubleshooter/1668960?rd=1#ts=1665119,1665157,2769079
尝试使用TLS而不是ssl也可以在端口587上运行一点。我注意到谷歌有这些问题。在这里检查它们的设置:https://support.google.com/mail/troubleshooter/1668960?r =1#ts=1665119、1665157、2769079
You can also refer to this: Send email using the GMail SMTP server from a PHP page. You will even discover more there.
您还可以参考以下内容:使用GMail SMTP服务器从PHP页面发送电子邮件。你会发现更多。
Now try this snippet
现在试试这个片段
<?php $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) {echo "$errstr ($errno)<br />\n";} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);} ?>
If you get an error, it means your server doesn't support the mailing functions. You need to host your project in a different one or you can change the server setting if you have access.
如果出现错误,则意味着服务器不支持邮件功能。您需要在一个不同的服务器上托管您的项目,或者您可以在有访问权限的情况下更改服务器设置。
Hope helped.
希望帮助。
#1
0
Try to use TLS instead of ssl also play a bit the port 587. I have noticed that google has these problems. Check their settings here: https://support.google.com/mail/troubleshooter/1668960?rd=1#ts=1665119,1665157,2769079
尝试使用TLS而不是ssl也可以在端口587上运行一点。我注意到谷歌有这些问题。在这里检查它们的设置:https://support.google.com/mail/troubleshooter/1668960?r =1#ts=1665119、1665157、2769079
You can also refer to this: Send email using the GMail SMTP server from a PHP page. You will even discover more there.
您还可以参考以下内容:使用GMail SMTP服务器从PHP页面发送电子邮件。你会发现更多。
Now try this snippet
现在试试这个片段
<?php $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) {echo "$errstr ($errno)<br />\n";} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);} ?>
If you get an error, it means your server doesn't support the mailing functions. You need to host your project in a different one or you can change the server setting if you have access.
如果出现错误,则意味着服务器不支持邮件功能。您需要在一个不同的服务器上托管您的项目,或者您可以在有访问权限的情况下更改服务器设置。
Hope helped.
希望帮助。