Issues sending email using my php form - php

I am trying to set up a simple "Contact Me" form for my website using VB.NET 2015. But I am not able to receive any emails. Here are my files:
PHP:
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
//if "email" variable is filled out, send email
$email = htmlspecialchars($_POST["email"], ENT_QUOTES);
$subject = htmlspecialchars($_POST["subject"], ENT_QUOTES);
$comment = htmlspecialchars($_POST["comment"], ENT_QUOTES);
$comment = str_replace("\n.", "\n..", $comment);//message can't have \n.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: " . $email . "\r\n";
if(mail("foo#test.com ", $subject, $comment, $headers)){
//no error
exit;
}
echo "Error sending mail";
?>
TYPESCRIPT:
module OnlinePortfolio {
export class ContactMe {
public static Email() {
$.ajax({
url: "SendMail.php",
type: "POST",
data: {
"subject": $("#subject").text(), "email": $("#email").text(), "message": $("#comment").text()
},
success: function (data, status) {
if (data === "") {
alert("Message sent successfully");
}
else {
alert("There was an issue with sending your message");
}
},
error: function (xhr, status, errorDescription) {
console.error('Something happened while sending the request: ' + status + ' - ' + errorDescription);
}
});
}
}
}
HTML
<html>
<form>
Email: <input id="email" type="text" /><br />
Subject: <input id="subject" type="text" /><br />
Message:<br />
<textarea id="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" onclick="OnlinePortfolio.ContactMe.Email()">
</form>
<html>
The email provided above is just for this post. I am fairly new to php but based on some research I did this should be working. I get no errors when I click the submit button. I also opened the debug console and get no errors as well. Can someone please help me understand why I am not receiving emails?
Many thanks in advance!

Please, use PHPMailer(https://github.com/PHPMailer/PHPMailer)) from local

It seems like you are using PHP in-built mail function. Unfortunately, It will not work on localhost.
You need to run that from a remote server to make it work.
In case, if you want to run that from localhost, use a third party library say phpmailer.

1:localhost can`t use mail() for send e-mail , first upload to server . if you must use in localhost use phpmailer (https://github.com/PHPMailer/PHPMailer)
2:your not set action ! in real html script set it

Related

PHP mail() form doesn't complete sending e-mail

<?php
ini_set("mail.log", "/tmp/mail.log");
ini_set("mail.add_x_header", TRUE);
define("TITLE", "Contact Us | MicroUrb");
include('includes/header.php');
/*
NOTE:
In the form in contact.php, the name text field has the name "name".
If the user submits the form, the $_POST['name'] variable will be automatically created and will contain the text they typed into the field. The $_POST['email'] variable will contain whatever they typed into the email field.
PHP used in this script:
pre_match()
- Perform a regular expression match
- http://ca2.php.net/preg_match
$_POST
- An associative array of variables passed to the current script via the HTTP POST method.
- http://www.php.net/manual/en/reserved.variables.post.php
trim()
- Strip whitespace (or other characters) from the beginning and end of a string
- http://www.php.net/manual/en/function.trim.php
exit
- output a message and terminate the current script
- http://www.php.net/manual/en/function.exit.php
die()
- Equivalent to exit
- http://ca1.php.net/manual/en/function.die.php
wordwrap()
- Wraps a string to a given number of characters
- http://ca1.php.net/manual/en/function.wordwrap.php
mail()
- Send mail
- http://ca1.php.net/manual/en/function.mail.php
*/
?>
<div id="contact">
<hr>
<h1 class="contact">Get in touch with us!</h1>
<?php
// Check for header injections
function has_header_injection($str) {
return preg_match("/[\r\n]/", $str);
}
if (isset($_POST['contact_submit'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$msg = $_POST['message'];
// Check to see if $name or $email have header injections
if (has_header_injection($name) || has_header_injection($email)) {
die(); // If true, kill the script
}
if (!$name || !$email || !$msg) {
echo '<h4 class="error">All fields required.</h4>Go back and try again';
exit;
}
// Add the recipient email to a variable
$to = "renaissance.scholar2012#gmail.com";
// Create a subject
$subject = "$name sent you a message via your contact form";
// Construct message
$message = "Name: $name\r\n";
$message .= "Email: $email\r\n";
$message .= "Message:\r\n$msg";
// If the subscribed checkbox was checked
if (isset($_POST['subscribe']) && $_POST['subscribe'] == 'Subscribe') {
// Add a new line to message variable
$message .= "\r\n\r\nPlease add $email to the mailing list.\r\n";
}
$message = wordwrap($message, 72);
// Set mail headers into a variable
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email> \r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
// Send the email
mail($to, $subject, $message, $headers);
?>
<!-- Show success message afte email has been sent -->
<h5>Thanks for contacting MicroUrb!</h5>
<p>Please allow 24 hours for a response.</p>
<p>« Go to Home Page</p>
<?php } else { ?>
<form method="post" action="" id="contact-form">
<label for="name">Your name</label>
<input type="text" id="name" name="name">
<label for="email">Your email</label>
<input type="email" id="email" name="email">
<label for="message">and your message</label>
<textarea id="message" name="message"></textarea>
<input type="checkbox" id="subscribe" name="name" value="Subscribe">
<label for="">Subscribe to newsletter</label>
<input type="submit" class="button next" name="contact_submit" value="Send Message">
</form>
<?php } ?>
<hr>
</div>
<?php include('includes/footer.php'); ?>
I've tried creating a simple mail form. The form itself is on my contact.php page. I would like to test that the code submits perfectly and sends the email.
I knew that there would be a chance that via MAMP or MAMP Pro the sending of the email would not work, but I have found documentation that says you can make it work. I followed this documentation:
https://gist.github.com/zulhfreelancer/4663d11e413c76c6393fc135f72a52ce
and it did not work for me. I have tried reaching out to the author to no avail.
This is what I have tried to do thus far:
I have made sure error reporting is enabled and set to report all errors and I have that code in my index.php file here:
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');
define("TITLE", "Home | MicroUrb");
include('includes/header.php');
?>
<div id="philosophy">
<hr>
<h1>MicroUrb's Philosophy</h1>
<p>Here at MicroUrb we guarantee you organically grown produce, because we grew it ourselves and we are local. We're not pompous, we're proud. We're proud of our work, our quality, our environment and our love for fresh local produce and family.</p>
<p>Thank you, from your local urban family farm.</p>
<hr>
</div><!-- philosophy -->
<?php
include('includes/footer.php');
?>
If you look at my code in contact.php, you will see that the mail() function is being called.
I checked MAMP Pro logs and for Postfix I had nothing because Postfix appears to not be running (could this be the problem?) For the Apache logs I had this error:
unknown: warning: /etc/postfix/main.cf, line 696: overriding earlier entry: inet_protocols=all
sendmail: warning: /etc/postfix/main.cf, line 676: overriding earlier entry: inet_protocols=ipv4
sendmail: warning: /etc/postfix/main.cf, line 696: overriding earlier entry: inet_protocols=all
postdrop: warning: /etc/postfix/main.cf, line 696: overriding earlier entry: inet_protocols=all
but which was caused by following Step 2 of the link I shared above, where it directed me to add this:
myorigin = live.com
myhostname = smtp.live.com
relayhost = smtp.live.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
inet_protocols = ipv4
smtp_use_tls = yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
Line eight above was conflicting with inet_protocols = all, so I deleted line 8 above and the problem went away, but the original problem of not being able to send mail is still there.
I am not using an error suppression operator.
I may need to check to see if mail() returns true or false.
I checked spam folders of the email accounts I tried sending mail to.
I believe I have supplied all mail headers:
// Set mail headers into a variable
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email> \r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
I believe the recipient value is correct:
// Send the email
mail($to, $subject, $message, $headers);
I tried multiple email accounts, same issue.
I believe the form method matches the code.
Is Postfix on my MAMP Pro not working the problem?
I enabled PHP custom mail.log.
Should I just call it quits and use a different mailer or different way of developing my contact form in PHP that will be less of a headache?
So I believe my question is not a duplicate of the other posting in question is because as outline above, I have gone through the troubleshooting steps of that very SO posting and it has not solved my problem.
I can only guess my problem is either more specific to getting Postfix working on my MAMP Pro. I am not checking if mail() returns true or false correctly or I just may need to go with PHPMailer or some alternative.

Html/php email send [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am about to write a little html/php script. But I am not able to send data from the HTML form input to any email address or into any text file. I was already searching for possible solutions but nothing worked for me. The Browser replayed the php script. But no mail has been send. Any help will be appreciated. Thank you.
I recommend you use PHPMailer his use is very easy
Do not forget the action and method attributes in the <form> tag.
contents of html file
<form action="send.php" method="POST">
<input type="text" name="name" placeholder="Typ your name..." />
<input type="email" name="from" placeholder="Typ your e-mailaddress..." />
<textarea name="message" placeholder="Typ your message..."></textarea>
<button type="submit">Send E-mail</button>
</form>
contents of send.php
<?
if(isset($_POST)) {
$name = $_POST['name'];
$message = $_POST['message'];
$from = $_POSST['from'];
if(!empty($name) && !empty($message) {
$subject = 'message from '.$name;
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
//$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
// #SEE: http://php.net/manual/en/function.mail.php
if(mail('[YOUR-ADDRESS]', $subject, $message, $headers)) {
echo 'Thx 4 msg!';
}
else {
echo 'Oh nooos, The msg was not send.';
}
}
else {
echo 'You should provide the fields with some data..';
}
}
?>
One should first sanitize the user input obviously.
I think your issue is how to handle form data with some code, so you may be able to send an email or write form data to a file. This is where you see the difference between client-side and server-side. HTML is a language to describe documents, here your form: the text input name is going to describe a name, the form will send its data within the POST method, and so on. The file describing HTML is processed in your browser. And your browser don't send an email or write data... That's why you should use a server-side language such as PHP to get things done. PHP is great to help you process data and behave on different event... In your case, great for receiving data, analyze data and then send data through mails or save data into a file.
So now you may want to understand how to do so... Mail are a little tricky since you may need to configure things such as mail server, authentification and so one. Maybe a good solution is to try mails with a Google account or something like that... When it will be done, you may simply send an email like so:
<?php
$to = 'your#email.here';
$subject = 'Mail test';
$data = $_POST['name']; // if a `name` field exist and your form send its data through POST method
mail($to, $subject, $data);
Writing things to a file is simpler, it only request permissions to read and/or write a file.
<?php
$file = 'path/to/file';
file_put_contents($file, $_POST['name'] . ' for example');
So this is globally everything:
index.html HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Form</title>
</head>
<body>
<form action="process.php" method="post">
<input name="name" type="text" placeholder="Name" />
<input type="submit" value="Process">
</form>
</body>
</html>
and process.php PHP file
<?php
/**
* Testing data
*/
if (!isset($_POST['name'])) {
die('No value `name` found');
}
/**
* Configuring process
*/
$to = 'your#email.here';
$subject = 'Mail test';
$data = $_POST['name'];
/**
* Saving data
*/
$res = file_put_contents(
'data.txt',
$data."\r\n"
);
if ($res !== false) {
echo 'data saved'.PHP_EOL;
} else {
echo 'error while saving data'.PHP_EOL;
}
/**
* Sending email
*/
$res = mail(
$to,
$subject,
$data
);
if ($res === true) {
echo 'mail sent';
} else {
echo 'error while sending mail'.PHP_EOL;
}
I suggest you to read mail() and file_put_contents() documentations to understand their behavior in case there are errors... :)

How do I validate my email submission on php?

I'm just getting into coding and put together a webpage using dreamweaver. I created a php page with my email coding which is executed from a form and submit button on an html page. I continously recieve blank emails on a daily basis which apparently means I need to add validation coding. I tried adding the coding but the problem persists. The page still submits even if the form is blank.
Below is my current coding.
<?php
if(!filter_var($_POST['CustomerEmail'], FILTER_VALIDATE_EMAIL)) { $valerrors[] = "The email address you supplied is invalid." ;}
$customeremail=$_POST['CustomerEmail'];
$email='test#gmail.com';
$custfirst=$_POST['CustomerFirstName'];
$custlast=$_POST['CustomerLastName'];
$custphone=$_POST['CustomerNumber'];
$custaddress=$_POST['CustomerAddress'];
$custcity=$_POST['CustomerCity'];
$custstate=$_POST['CustomerState'];
$custrequest=$_POST['CustomerService'];
$subject='Service Request';
$body = <<<EOD
<br><hr><br>
Email: $customeremail <br>
First Name: $custfirst <br>
Last Name: $custlast <br>
Phone: $custphone <br>
Address: $custaddress <br>
City: $custcity <br>
State: $custstate <br>
Request: $custrequest <br>
EOD;
$headers = "From: $customeremail\r\n";
$headers .= "Content-type: text/html\r\n";
$Send = mail($email, $subject, $body, $headers);
$confirmation = <<<EOD
<html>"Thanks for Submitting."</html>
EOD;
echo"$confirmation";
?>
It's possible that I'm placing the if statement in the wrong place. Can someone correct my coding so the confirmation page will not load and the email will not be sent if the customer email is left blank?
You need to check like this
if (filter_var('abc#gmail.com', FILTER_VALIDATE_EMAIL)) {
echo 'VALID';
} else {
echo 'NOT VALID';
}
see here : http://php.net/manual/en/function.filter-var.php
You could initialize $valerrors = []; at the beginning and use a condition such as:
if (empty($valerrors)) {
$headers = "From: $customeremail\r\n";
$headers .= "Content-type: text/html\r\n";
$Send = mail($email, $subject, $body, $headers);
$confirmation = <<<EOD
<html>"Thanks for Submitting."</html>
EOD;
}
Note that you should apply similar validation to all user inputs.
I think u can add "required" attribute to your email input in your form Html
<input type="email" name="CustomerEmail" required>
So Html wont allow you to submit until you provide a value

not receiving form emails

I tried earlier with no solution, so I'm adding all my code to try and resolve this issue. I am not getting this form in my inbox, but my ajax function is working like it should. I have godaddy hosting, and am running it locally on wampp for mac. I've tried multiple different email addresses with no avail. I don't want to use php mailer. I just want this to function properly instead of what it seems to be doing which is shooting emails into outter space
html
<div class="block">
<div class="done">
<h1>Thank you! I have received your message.</h1>
</div>
<div class="form">
<form method="post" action="scripts/process.php">
<input name="name" class="text" placeholder="Name" type="text" />
<input name="email" class="text" placeholder="Email" type="text" />
<textarea name="comment" class="text textarea" placeholder="Comment"></textarea>
<input name="submit" value="Let's Go!" id="submit" type="submit" />
<div class="loading"></div>
</form></div>
</div>
<div class="clear"></div>
</div>
</div>
jquery validation and ajax
$('#submit').click(function () {
//Get the data from all the fields
var name = $('input[name=name]');
var email = $('input[name=email]');
var comment = $('textarea[name=comment]');
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
var emailVal = email.val();
//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
if (!emailReg.test(emailVal)){
email.addClass('hightlight');
return false;
} else email.removeClass('hightlight');
if (name.val()=='') {
name.addClass('hightlight');
}else{name.removeClass('hightlight');}
if (email.val()=='') {
email.addClass('hightlight');
}else{email.removeClass('hightlight');}
if (comment.val()=='') {
comment.addClass('hightlight');
}else{email.removeClass('hightlight');}
if (name.val()=='' || email.val()=='' || comment.val()=='') {
return false;
}
//organize the data properly
var data = 'name=' + name.val() + '&email=' + email.val() + '&website='
+ website.val() + '&comment=' + encodeURIComponent(comment.val());
//disabled all the text fields
$('.text').attr('disabled','true');
//show the loading sign
$('.loading').show();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "scripts/process.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (send mail success)
if (html==1) {
//hide the form
$('.form').fadeOut('slow');
//show the success message
$('.done').fadeIn('slow');
//if process.php returned 0/false (send mail failed)
} else alert('Sorry, unexpected error. Please try again later.');
}
});
//cancel the submit button default behaviours
return false;
});
and the php which I regret to say I know very little about for now
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$comment) $errors[count($errors)] = 'Please enter your comment.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - change this to your name and email
$to = 'myemail#gmail.com';
//sender
$from = $name . ' <' . $email . '>';
//subject and the html message
$subject = 'Comment from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! Matt has received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
There are so many issues on sending PHP mails to different mail servers. For example, when I want to send email to GMail hosts I never include \r for new lines and I only go with \n. Maybe your problem is with your headers, I place my code here and see what you can get:
function send($address, $subject, $content, $from = '', $html = FALSE, $encoding = 'utf-8')
{
if(empty($address) || empty($content)) return;
$headers = "";
if($from != '')
{
$headers .= "From: {$from}\n";
$headers .= "Reply-To: {$from}\n";
}
$headers .= "To: {$address}\n";
if($html)
{
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset={$encoding}\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
}
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$headers .= "X-Mailer: PHP/" . phpversion();
set_time_limit(30);
mail($address, $subject, $content, $headers);
}
send('myemail#myhost.com', 'title', 'content', 'myemail <myemail#myhost.com>', FALSE);

Sending Email via PHP Not Working

I have a site running on Windows Azure that contains a simple contact form for people to get in touch. Unfortunately, that form isn't work right now...
I have an index.php file that contains the form:
<div class="form">name="name" placeholder="Name" id="contactname" />
<input type="text" name="email" placeholder="Email" id="contactemail" />
<textarea name="message" placeholder="Message" id="contactmessage"></textarea>
<button>Contact</button>
</div>
I then have a JS file like this:
if ($('#contact').is(":visible")) {
$("#contact button").click(function() {
var name = $("#contactname").val();
var message = $("#contactmessage").val();
var email = $("#contactemail").val();
var emailReg = /^[a-zA-Z0-9._+-]+#[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$/;
// client-side validation
if(emailReg.test(email) == false) {
var emailValidation = false;
$('#contactemail').addClass("error");
}
else
$('#contactemail').removeClass("error");
if(name.length < 1) {
var nameValidation = false;
$('#contactname').addClass("error");
}
else
$('#contactname').removeClass("error");
if(message.length < 1) {
var messageValidation = false;
$('#contactmessage').addClass("error");
}
else
$('#contactmessage').removeClass("error");
if ((nameValidation == false) || (emailValidation == false) || (messageValidation == false))
return false;
$.ajax({
type: "post",
dataType: "json",
url: "send-email.php",
data: $("#contact").serialize(),
success: function(data) {
$('.form').html('<p class="success">Thanks for getting in touch - we\'ll get back to you shortly.</p>');
}
});
return false;
});
};
and finally, a php file to send the email called send-email.php:
$destination = 'info#clouddock.co'; // change this to your email.
// ##################################################
// DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
// ##################################################
$email = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
$subject = $name;
$headers = "From: ".$name." <".$email.">\r\n" .
"Reply-To: ".$name." <".$email.">\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
mail($destination, $subject, $message, $headers);
}
When I fill in the contact form, the JS validation appears to be working, and when I click send the 'Thanks for getting in touch...' text appears, as if the message has been sent. But I don't receive any email. Can anyone advise as to where the problem might be? Could it be Azures configuration blocking the messages from being sent out?
You are using $("#contact").serialize() to get data to send but you've got no elements with ID contact.
You should use $("#contactname, #contactemail, #contactmessage").serialize() (and fix first input ;) ).
And always validate input data in PHP, not only in JS!
Of course it will display the thanks message, all it needs is a response back from the server. What you need is to test whether the mail actually sent or not, then return that back to your original script to determine what message to show.
if(mail($destination, $subject, $message, $headers)) {
return '<p class="success">Thanks for getting in touch - we\'ll get back to you shortly.</p>';
} else {
return '<p class="fail">The e-mail failed to send.</p>';
}
And then set your AJAX to:
$.ajax({
type: "post",
url: "send-email.php",
data: $("#contact").serialize(),
success: function(data) {
$('.form').html(data);
}
});
You'll probably find that you get the fail message, and that could well be the setup of your server, or it could be you not passing the right thing to the mail() function. You then need to debug your script to find out whether the right information is being passed etc.
With Windows servers they need to be configured to pass all mail from the mail() function to an SMTP server, so if that's not been done on your Azure server then your mail will instantly fail.

Categories