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