Need SMTP authentication in my PHP form? - php

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> → <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" />
← <span class="REQ">*</span>Departure Date
</td>
</tr>
<tr>
<td width="50%" align="right" style="text-align: right;">
Adults<span class="REQ">*</span> →
<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>
← <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://thebunchofgrapesinn.com/apartments_reservation
I am not sure how to add SMTP authentication and what is wrong here, can someone help?

The behavior of php's mail() function varies depending on the server OS. Windows doesn't have a built in non-SMTP option like Unix-based servers. mail() is also limited in general without some advanced knowledge of working with headers.
If it's not inappropriate here to recommend a tool for the job, PHPMailer is a convenient enough goto solution for sending email from php. If your server is Unix/Linux based, you can leave out $mail->isSMTP() and the related options and PHPMailer will use the server's sendmail implementation. If you are on Windows or have SMTP details handy, PHPMailer makes that simple enough.

You can use PHPMailer and Swiftmailer, these are common libraries for sending smtp mails. PhpMailer is a little simpler than swift and documentations is easy to understand.
But you can write your own smtp client for this but first you need to learn how to make a socket connection in php. PHPMailers smtp class is a good hint to create one.
If you have administrator rights for your server, you can connect your sendmail mail function to a smtp server, here is a documantation how to. Php has a mail configuration option for smtp though i never used it before.
By the way, php.ini has a sendmail_path option to read your STDOUT data and send mail. If you want, you can change this sendmail_path param with a bash, php, or a python script. But i do not recommend it.

Most of the host have SMTP already configured.In order to debug test mail() function seperately.Just make a file like 'mail.php' and put the below code in to it :
<?php
$email ="PUT EMAIL ID OF USER HERE";
$subject ="Reservation Info";
$headers = "From: " . '<thebunchofgrapesinn.com/>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html>
<body>
<p>Its Just A Testing Mail</p>
</body>
</html>";
if(mail($email,$subject, $message, $headers)){
echo 'mail sent';
}
?>
Check weather it works or not.Also prefer to use phpmailer.Here is the link for downloding PHPmailer class it also has example.

Related

Contact Form not sending all data

I have a problem with my contact form
Filling in the form is OK etc, but when I send the message, I only receive the telephone nr.
This is PHP code from sendmail.
<?php
if (isset($_POST["submit"])) {
// Checking For Blank Fields..
if ($_POST["name"] == "" || $_POST["email"] == "" || $_POST["tel"] == "") {
echo "Fill All Fields..";
} else {
// Check if the "Sender's Email" input field is filled out
$email = $_POST['email'];
// Sanitize E-mail Address
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email) {
echo "Invalid Sender's Email";
} else {
$subject = 'neuen Kontakt';
$message = $_POST['name'];
$message = $_POST['email'];
$message = $_POST['tel'];
$headers = 'From:' . $email2 . "\r\n"; // Sender's Email
$headers .= 'Cc:' . $email2 . "\r\n"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
//$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("mymail#gmail.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly ! Thank you for your feedback";
}
}
}
?>
and this is the html form
<form action="index.php" method="post" name="contactus" id="contactus" onsubmit="return ValidateForm();">
<table width="260" border="0" cellspacing="0" cellpadding="0" align="center" style="color:#FFF">
<tr>
<td height="25px" style="font-family:Arial; font-size:13px; color:#575757; padding:0 0 0 10px;">Name<span style="color:#F00">*</span>
</td>
</tr>
<tr>
<td style="padding:0 0 0 10px;">
<input name="name" type="text" class="input" id="name" onFocus="inputFocus(this)" onBlur="inputBlur(this)" value="" />
</td>
</tr>
<tr>
<td height="27px" style="font-family:Arial; font-size:13px; color:#575757; padding:0 0 0 10px;">Telefonnummer<span style="color:#F00">*</span>
</td>
</tr>
<tr>
<td class="td_style1">
<input name="tel" type="text" class="input" id="email" onFocus="inputFocus(this)" onBlur="inputBlur(this)" value="" />
</td>
</tr>
<tr>
<td height="25px" style="font-family:Arial; font-size:13px; color:#575757; padding:0 0 0 10px;">E-mail<span style="color:#F00">*</span>
</td>
</tr>
<tr>
<td style="padding:0 0 0 10px;">
<input name="email" type="text" class="input" id="email" onFocus="inputFocus(this)" onBlur="inputBlur(this)" value="email#gmail.com" />
</td>
</tr>
<tr>
<td style="padding:10px 28px 0 0;" align="right">
<input name="submit" type="submit" value="SUBMIT" class="submit" />
</td>
</tr>
<tr>
<td height="20px" style="font-family:Arial; font-size:11px; color:#575757; padding:3px 27px 0 0px; float:right;"><span style="color:#F00">*</span> sind Pflichtfelder</td>
</tr>
</table>
You overwrite the $message with each field so you will get only the last one (tel). You need to concatenate all the fields using . like this:
$message = $_POST['name'] . ", ";
$message .= $_POST['email'] . ", " ;
$message .= $_POST['tel'];
Or you can do in one line like this:
$message = $_POST['name'] . ", " . $_POST['email'] . ", " . $_POST['tel'];
Also you can add a comma or something like that between the fields so will not be glued together.
You are replacing value of $message everytime with new value , and at end it is assigned to telephone so u only recieve telephone no
Replace
$message = $_POST['name'];
$message = $_POST['email'];
$message = $_POST['tel'];
With
$message =$_POST['name'];
$message =$message.$_POST['email'];
$message =$message.$_POST['tel'];

Run PHP Code After Form Submission And Redirect

I want to run some php code after a form is submitted on my website. It redirects to another page to email the information, then uses header() to return to the previous page. What I would like to happen is to load a small message that shows that the message was sent successfully, but I'm not sure how to do this after being redirected from another page. I'm hoping to use php or jquery to accomplish this, and I'm including the code I'm using below. I have tried to use the session_start function to do this, but the echoed text remains on the page after the user leaves.
<form method="post" action="mail.php">
<tr>
<td class="label">Name:</td>
<td class="input"><input type="text" maxlength="40" name="name" pattern="[a-zA-Z0-9]+" title="Please enter your name." required></td>
</tr>
<tr>
<td class="label">Email:</td>
<td class="input"><input type="email" maxlength="24" name="email" title="Please enter an email address." required></td>
</tr>
<tr>
<td class="label">Subject:</td>
<td class="input"><input type="text" maxlength="24" name="subject" title="Please enter a subject." required></td>
</tr>
<tr>
<td class="label">Message:</td>
<td class="input"><textarea rows="9" maxlength="1000" name="message" title="Please enter a message." required></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Submit">
</td>
</tr>
</form>
<?php
$to = "kouen922#gmail.com";
$subject = "Message From Your Website: ".trim(htmlspecialchars($_POST["subject"]));
$message = trim(htmlspecialchars($_POST["message"]));
$headers = "Reply To: ".trim(htmlspecialchars($_POST["email"]))."" ."\r\n". "From: " .trim(htmlspecialchars($_POST["name"]))."";
mail($to,$subject,$message,$headers);
header("Location: index.php#contact");
?>
Easy.
header("Location: index.php?thankyou#contact");
Then do a conditional for isset($_GET['thankyou']) and print out a message.
Instead of using php, use Jquery(since you mentioned about it) and use its potential to send your form data, using ajax post request. In that way you can stay on same page without ever navigating to another page(because you are returning back), and also you can display the message once the post request is complete, ajax POST method returns a callback once the request is complete
Read about it here
According to your description: form page -- php email page -- back to form page, then just add the php email part into form page:
index.php:
<?php
$data = init_data();
if ($data['cmd']) {
$err = main_send($data);
}
if (!$data['cmd'] || $err) {
main_form($data, $err);
}
function init_data() {
$arr = ['cmd', 'name', 'email', 'subject', 'message'];
foreach ($arr as $k) {
$data[$k] = isset($_POST[$k]) ? trim(htmlspecialchars($_POST[$k])) : '';
}
return $data;
}
function main_send($data) {
if (!$data['name']) {
return 'What is your name?';
} elseif (!$data['email']) {
return 'What is your email?';
} elseif (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
return 'Your email is not valid';
} elseif (!$data['message']) {
return 'Please say something';
}
$to = 'kouen922#gmail.com';
$subject = 'Message From Your Website: ' . $data['subject'];
$message = trim(htmlspecialchars($_POST["message"]));
$headers = 'Reply To: ' . $data['email'])) . "\r\nFrom: " . $data['name']));
mail($to, $subject, $message, $headers);
echo '<p>Thank you very much for the feedback</p>';
}
function main_form($data, $err = '') {
if ($err) {
echo '<p class="err">' , $err , '</p>';
}
echo 'your original form html here ...';
}
Try this code:
form code
<div id="message"></div>
<form method="post" id="email-form" action="">
<tr>
<td class="label">Name:</td>
<td class="input"><input type="text" maxlength="40" id="name" name="name" pattern="[a-zA-Z0-9]+" title="Please enter your name." required></td>
</tr>
<tr>
<td class="label">Email:</td>
<td class="input"><input type="email" maxlength="24" id="email" name="email" title="Please enter an email address." required></td>
</tr>
<tr>
<td class="label">Subject:</td>
<td class="input"><input type="text" maxlength="24" id="subject" name="subject" title="Please enter a subject." required></td>
</tr>
<tr>
<td class="label">Message:</td>
<td class="input"><textarea rows="9" id="message" maxlength="1000" name="message" title="Please enter a message." required></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Submit">
</td>
</tr>
</form>
email.php code
<?php
//email.php
$to = "kouen922#gmail.com";
$subject = "Message From Your Website: ".trim(htmlspecialchars($_POST["subject"]));
$message = trim(htmlspecialchars($_POST["message"]));
$headers = "Reply To: ".trim(htmlspecialchars($_POST["email"]))."" ."\r\n". "From: " .trim(htmlspecialchars($_POST["name"]))."";
mail($to,$subject,$message,$headers);
echo 'Mail was successfully send';
?>
Jquery code :
<script>
$(document).ready(function () {
$("#email-form").submit(function(event){
event.preventDefault();
var email= $('#email').val();
var name= $('#name').val();
var subject= $('#subject').val();
var messege = $('#messege').val();
$.ajax({
url: "email.php",
type:"POST",
data: 'email='+email + '&name='+name +'&subject='+subject+'&message='+message,
success: function(data){
$('#message').html(data);
setTimeout(function(){ //redirect after 5 sec
window.history.go(-1); // Simulates a back button click
},5000); // time in milli sec
}
});
});
});
</script>

contact form not sending to email cakephp

i'm new in php..i would like to sent contact form to my gmail account..
everything just going fine whrn i click the submit button,but my problem is this form not sending me the email..
this is my html code
<form action="kontact-sent" onSubmit="return validate_form(this)" method="post">
<table width="415" border="0" cellspacing="1" cellpadding="5" class="t1">
<tr>
<td align="left" valign="top" bgcolor="#efefef">First name:<br /><input name="FirstName" type="text" id="FirstName" style="width:300px;" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef">Email address<br /><input type="text" name="EmailAddress" id="EmailAddress" style="width:300px;" />
<input name="Email_Confirmation" class="Email_Confirmation2"/></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef">Message<br /><textarea name="Inquiry" id="Inquiry" style="width:300px; height:100px;"></textarea></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
function validate_EmailAddress(field,alerttxt){
with (field)
{
apos=value.indexOf("#");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(FirstName,"Please enter your First Name.")==false)
{FirstName.focus();return false;}
if (validate_EmailAddress(EmailAddress,"Please enter a valid Email Address.")==false)
{EmailAddress.focus();return false;}
if (validate_Inquiry(Inquiry,"Please enter your Inquiry.")==false)
{Inquiry.focus();return false;}
}
}
this is my .php
<?php
// if the Email_Confirmation field is empty
if(isset($_POST['Email_Confirmation']) && $_POST['Email_Confirmation'] == ''){
// put your email address here scott.langley.ngfa#statefarm.com, slangleys#yahoo.com
$youremail = 'afiqrashid91#gmail.com';
// prepare a "pretty" version of the message
$body .= "Thank You for contacting us! We will get back with you soon.";
$body .= "\r\n";
$body .= "\r\n";
foreach ($_POST as $Field=>$Value) {
$body .= "$Field: $Value\r\n";
$body .= "\r\n";
}
$CCUser = $_POST['EmailAddress'];
// Use the submitters email if they supplied one
// (and it isn't trying to hack your form).
// Otherwise send from your email address.
if( $_POST['EmailAddress'] && !preg_match( "/[\r\n]/", $_POST['EmailAddress']) ) {
$headers = "From: $_POST[EmailAddress]";
} else {
$headers = "From: $youremail";
}
// finally, send the message
mail($youremail, 'Form request', $body, $headers, $CCUser );
}
// otherwise, let the spammer think that they got their message through
?>
Thank You for contacting us! We will get back with you soon.
i hope that anyone can help me..thanks in advance..
$headers = "From: $_POST[EmailAddress]";
Should be:
$headers = "From: $_POST['EmailAddress']";
Also, email messages shouldn't exceed 70 characters per line. You'll want to fix this by adding:
$body = wordwrap($body, 70);

Php email send issue

Following is my HTML Select field which gets all the emails from my database. Now I'm trying to send single or multiple emails with php. But It doesn't send any emails. Can you tell me what is wrong with my code ?
Html Code:
<tr>
<td valign="top">To</td>
<td>
<select multiple="multiple" size="7" name="to[]">
<?php
$getemail = mysql_query("SELECT email FROM clients");
while($res = mysql_fetch_array($getemail)){
$email = inputvalid($res['email']);
echo "<option value='$email'>$email</option>";
}
?>s
</select>
</td>
</tr>
Php Code:
foreach($to as $total){
$total;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$mail = mail($total, $subject, $msg, $headers);
}
Update-Full Code:
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" />
<table width="400" border="0" cellspacing="10" cellpadding="0" style="float:left;
position:relative;">
<tr>
<td>Subject</td>
<td><input type="text" name="subject" value="<?php if(isset($_POST['subject'])) echo
$_POST['subject']; ?>" class="tr"/></td>
</tr>
<tr>
<td valign="top">Message</td>
<td><textarea name="msg" class="textarea_email"><?php if(isset($_POST['msg'])) echo
$_POST['msg']; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Send Message" class=" submit" name="Submit"/></td>
</tr>
</table>
<table style="float:left; position:relative; border:0px #000 solid;" width="400" border="0"
cellspacing="10" cellpadding="0">
<tr>
<td valign="top">To</td>
<td>
<select multiple="multiple" size="7" name="to[]">
<?php
$getemail = mysql_query("SELECT email FROM clients") or die(mysql_error());;
while($res = mysql_fetch_array($getemail)){
$email = inputvalid($res['email']);
echo "<option value='$email'>$email</option>";
}
?>s
</select>
</td>
</tr>
</table>
</form>
Php code:
if(isset($_POST['Submit']) && $_POST['Submit'] == "Send Message")
{
$subject = inputvalid($_POST['subject']);
$msg = inputvalid($_POST['msg']);
$to = $_POST['to'];
if(isset($subject) && isset($msg) && isset($to)){
if(empty($subject) && empty($msg) && empty($to))
$err[] = "All filed require";
}
else{
if(empty($to))
$err[] = "Please select email address";
if(empty($subject))
$err[] = "Subject require";
if(empty($msg))
$err[] = "Message require";
}
if(!empty($err))
{
echo "<div class='error'>";
foreach($err as $er)
{
echo "<font color=red>$er.</font>
<br/>";
}
echo "</div>";
echo "<br/>";
}
else{
foreach($to as $total){
echo $total;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$mail = mail($total, $subject, $msg,
$headers);
}
if($mail)
echo "<font color=green>Successfully sent your message. We will be get in
touch with you. Thank You.</font/><br/><br/>";
header("Refresh:10; url=email.php");
}
}
You can send multiple emails for one mail function.
Only pass email address with comma separated.
like "test#gmail.com,test1#gmail.com"
first make sure that you query is correct.
Change the following line:
$getemail = mysql_query("SELECT email FROM clients");
to
$getemail = mysql_query("SELECT email FROM clients") or die(mysql_error());
Change the following line:
$total;
to
echo $total . '<BR />';
Save and refresh the page
What is your output?
Do you get an errormessage?
Do you see emailadresses?
edit:
change the following line
$mail = mail($total, $subject, $msg, $headers);
to
if (!mail($total, $subject, $msg, $headers);) {
echo 'This is not working';
}
What is your result?
Check your apache-configs! I had the same problem on my local machine. as soon as i uploaded it on a fully configured Webserver, the code started to work! Maybe this solves your problem, too
Some time mail() function may not work so you should go with PHPMailer, for more details to use this, you can go through a good documentation :
Send mail using PHPMailer

Simple php contact form issue, not sending

Building a website for a client but the contact form is refusing to work, I set the client up with an email account 'contact#eunicedcolvin.co.uk' but it doesn't appear to finish sending it off to load the success message, here is the code below. Im fairly new to PHP but can't figure out what the issue is.
<div id="contact-form" style="background: none;">
<div id="contact-header"></div>
<div id="contact-middle">
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'contact#eunicedcolvin.co.uk';
$EmailSubject = 'Website Contact';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Comment: ".n12br($_POST["comment"])."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<div id="contact-success">
<span style="font-size:16px; font-weight:bold; ">Thanks! Your message was sent</span><br>
I will get back to you as soon as I can
</div>
</div>
<?php
} else {
?>
<form method="POST">
<table width="360" border="0" cellspacing="8" cellpadding="0" style="margin-left: 11px;">
<tbody><tr>
<td class="contact-label">Your name:<br></td>
<td class="contact-text-border"><input name="name" type="text" id="name" size="32" class="contact-name"></td>
</tr>
<tr>
<td class="contact-label">Your Email address:</td>
<td class="contact-text-border"><input name="email" type="text" id="email" size="32" class="contact-name"></td>
</tr>
<tr>
<td class="contact-label">Comment:</td>
<td class="contact-text-border" style="padding: 2px 2px;"><textarea name="comment" cols="45" rows="6" id="comment" class="contact-comment"></textarea></td>
</tr>
<tr>
<td height="33" class="contact-label"> </td>
<td align="left" valign="top">
<input type="submit" name="Submit" class="submit" value="."></td>
</tr>
</tbody></table>
</form>
<?php
};
?>
</div>
<div id="contact-bottom"></div>
</div>
</div>
if you'd like to see a sample of it live, its here: http://www.eunicedcolvin.co.uk/contact.html
link to website
The thing is, originally it was set up to post to my personal email to test, then when i swapped it over it refused to work! been racking my brains over this for a while now :S
Your email sending server is most likely not setup correctly.
If it is in fact sending, then its probably get spam filtered.
Also you should not set the from address to the submitted address in the form, as your server will not be authorized to send from that domain.
To try your server is configured mail or not :
if(#mail($emailRecipient, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
use this code, upload it to simple x.php file with just this code (mail etc is inserted),
you know that your server is just ok or not :)...
or might be it's put to spam folder of the receiver
Use SMTP.
Don't spend time trying to make mail work.... In my opinion it's just a waste of time, and most emails sent with it, end up in SPAM folder.

Categories