繁体   English   中英

梨邮件和谷歌验证码不起作用

[英]pear mail and google captcha do not work

我使用php 5.3.13,pear mail和google captcha(recaptcha)来创建一个简单的“联系我们”表单。

有一个电子邮件字段,一个主题字段和一个注释字段。 用户也解决了验证码,然后他可以按“发送”。

这在我的笔记本电脑本地工作正常,而不是在我安装网站的服务器上。 它完全相同的代码。

我使用一个简单的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');
?>

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();}

}
?>

当我以简单用户身份访问网站时,我收到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"

但仍然没有运气。 我错过了什么?

太感谢了

尝试使用TLS而不是ssl也玩端口587.我注意到谷歌有这些问题。 在此处查看其设置: https//support.google.com/mail/troubleshooter/1668960?rd = 1#ts = 1665119,1665157,2769079

您还可以参考: 从PHP页面使用GMail SMTP服务器发送电子邮件 你甚至会在那里发现更多。

现在试试这个片段

<?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);} ?>

如果出现错误,则表示您的服务器不支持邮件功能。 您需要在另一个项目中托管项目,或者如果您有权访问,则可以更改服务器设置。

希望有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM