mardi 31 mars 2015

Need SMTP authentication in my PHP form?

i have created a form and it doesnt send out emails. I contacted my host and he said I need SMTP authentication. Form needs to send reservation info.


Here is my reservation.php file:





<script>
/////////////////// RESERVATION FORM //////////////////////
$("#ajax-contact-form").submit(function(){
var str = $(this).serialize();
document.getElementById('submit').disabled=true;
document.getElementById('submit').value='PLEASE WAIT';
$.ajax({
type: "POST",
url: "apartments_reservation_send.php",
data: str,
success: function(msg){
$("#note").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
result = '<div class="notification_ok">Thank you!<br />Your request is successfully sent!</div>';
$("#fields").hide();
}
else
{
document.getElementById('submit').disabled=false;
document.getElementById('submit').value='Send request';
result = msg;
autoReinitialise: true;
}
$(this).html(result);
});
}
});
return false;
});
</script>

<form id="ajax-contact-form" action="javascript:alert('success!');">
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<td width="50%" align="right" style="text-align: right;">
Arrival Date<span class="REQ">*</span> &rarr; <input id="arrivalDate" name="arrivalDate" size="30" type="text" class="date-pick" />
</td>
<td width="50%" align="left" style="text-align: left;">
<input id="departureDate" name="departureDate" size="30" type="text" class="date-pick" />
&larr; <span class="REQ">*</span>Departure Date
</td>
</tr>
<tr>
<td width="50%" align="right" style="text-align: right;">
Adults<span class="REQ">*</span> &rarr;
<select id="Adults" name="Adults">
<option value=""></option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
<td width="50%" align="left" style="text-align: left;">
<select id="Children" name="Children">
<option value=""></option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
&larr; <span class="REQ">*</span>Children
</td>
</tr>
</table>
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<td width="25%" align="right" valign="middle" style="text-align: right;">Name<span class="REQ">*</span> :</td>
<td width="75%" align="left" style="text-align: left;">
<input type="text" id="name" name="name" value="" size="86" />
</td>
</tr>
<tr>
<td align="right" valign="middle" style="text-align: right;">E-mail<span class="REQ">*</span> :</td>
<td align="left" style="text-align: left;">
<input type="text" id="email" name="email" value="" size="86" />
</td>
</tr>
<tr>
<td align="right" valign="middle" style="text-align: right;">Phone<span class="REQ">*</span> :</td>
<td align="left" style="text-align: left;">
<input type="text" id="phone" name="phone" value="" size="86" />
</td>
</tr>
<tr>
<td align="right" style="text-align: right;">Message :</td>
<td align="left" valign="top" style="text-align: left;">
<textarea id="message" name="message" rows="5" cols="87"></textarea>
</td>
</tr>
<tr>
<td width="100%" align="center" style="text-align: center;" colspan="2">
<input class="button" type="submit" name="submit" id="submit" value="Send request" />
</td>
</tr>
</table>
</form>



and here is my reservarion_send.php:





<?php

$TO_EMAIL = "info@thebunchofgrapesinn.com";
$FROM_EMAIL = "info@thebunchofgrapesinn.com";
$FROM_NAME = "thebunchofgrapes.com";
$SUBJECT = "The Bunch Og Grapes - Apartment Reservation";
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;

if($post)
{
include 'functions.php';

$ARIVAL_DATE = trim($_POST['arrivalDate']);
$DEPARTURE_DATE = trim($_POST['departureDate']);
$ADULTS = trim($_POST['Adults']);
$CHILDREN = trim($_POST['Children']);
$EMAIL = trim($_POST['email']);
$PHONE = trim($_POST['phone']);
$NAME = stripslashes($_POST['name']);
$MESSAGE = stripslashes($_POST['message']);

$ERROR = '';
if(!$ARIVAL_DATE)
{
$ERROR .= 'Please enter Arrival Date<br />';
}
if(!$DEPARTURE_DATE)
{
$ERROR .= 'Please enter Departure Date<br />';
}
//if(!$ADULTS)
//{
//$ERROR .= 'Please pick number of Adults<br />';
//}
//if(!$CHILDREN)
//{
//$ERROR .= 'Please pick number of Children<br />';
//}
if(!$NAME)
{
$ERROR .= 'Please enter Your Name.<br />';
}
if(!$EMAIL)
{
$ERROR .= 'Please enter Email address.<br />';
}
if($EMAIL && !ValidateEmail($EMAIL))
{
$ERROR .= 'Please enter valid Email address.<br />';
}
if(!$PHONE)
{
$ERROR .= 'Please enter You Phone Number.<br />';
}
//if(!$MESSAGE || strlen($MESSAGE) < 15) {
//$ERROR .= "Molimo unesite poruku. <br />Poruka mora imati najmanje 15 karaktera.<br />";
//}

$FULL_MESSAGE = "ARIVAL DATE = $ARIVAL_DATE\nDEPARTURE DATE = $DEPARTURE_DATE\nADULTS = $ADULTS\nCHILDREN = $CHILDREN\nNAME = $NAME\nEMAIL = $EMAIL\nPHONE = $PHONE\nMESSAGE = $MESSAGE";

if(!$ERROR)
{
$mail = mail($TO_EMAIL, $SUBJECT, $FULL_MESSAGE,
"From: ".$FROM_NAME." <".$FROM_EMAIL.">\r\n"
."Reply-To: ".$FROM_EMAIL."\r\n"
."X-Mailer: PHP/" . phpversion());

if($mail) {
echo 'OK';
}
}
else {
echo '<div class="notification_error">'.$ERROR.'</div>';
}

}
?>



and here is the link of the webpage http://ift.tt/1DkxbTS


I am not sure how to add SMTP authentication and what is wrong here, can someone help?


Aucun commentaire:

Enregistrer un commentaire