7

I use php 5.3.13 ,pear mail and google captcha (recaptcha) to create a simple "contact us" form.

There is an email field, a subject field and a comments field. User has also solve the captcha and then he can press "Send".

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

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

<?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?

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

[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

slevin
  • 4,166
  • 20
  • 69
  • 129
  • Check you backend. If you trying to use the schools SMTP, they may have prevented that. You could use php mail as the backend and that would bypass the schools SMTP. see the notes here [PEAR] (http://pear.php.net/manual/en/package.mail.mail.factory.php). You can try `code`$mail_object =& Mail::factory('mail', '-f bounce@domain.com') ;`code` – rwhite Jan 10 '14 at 21:39
  • Also is PEAR available on the schools server? – Jeremy Harris Jan 10 '14 at 21:45
  • @cillosis Good question. I dont know for sure, but I guess it is. As I said, my code was working fine on my laptop (locally) and since I transfer it to the server, does not. So, since my code was working, I guess PEAR is availiable. – slevin Jan 10 '14 at 21:55
  • Working on your laptop indicates your local environment has everything you need. That **does not** mean the server does. – Jeremy Harris Jan 10 '14 at 21:56
  • @cillosis But I was accessing school's smtp via my laptop also – slevin Jan 10 '14 at 22:07
  • Ok, but when you called `Mail::factory` it was in a PHP file hosted on your laptop running a local instance of PHP (and consequently a local PEAR install which included the Mail package). What SMTP server you used is inconsequential. When the PHP file is on the school's servers, it then relies on those dependencies to be available **there**. – Jeremy Harris Jan 10 '14 at 22:10
  • @rwhite35 Is there a way to use the gmail? – slevin Jan 10 '14 at 22:20
  • @cillosis I updated the question, with more info. Can you please take a llok, maybe will spot the error. Thanks again for your time – slevin Jan 18 '14 at 00:47
  • 1
    **What is the error?** 500 is HTTP status code. It's not an error. [Enable PHP error reporting](http://blog.flowl.info/2013/enable-display-php-errors/) or take a look into the log files. We can't help otherwise – Daniel W. Jan 19 '14 at 14:09
  • If you're trying to send emails using your Uni's SMTP server, identify as something@gmail.com you're going to have issues. It could be possible that your University wouldn't allow you to use a non-university email. – Someguy123 Jan 25 '14 at 06:59

1 Answers1

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

You can also refer to this: Send email using the GMail SMTP server from a PHP page. You will even discover more there.

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.

Community
  • 1
  • 1
ZooBoole
  • 31
  • 7