Trying to send mail from localhost using mail(), no mail is received. I am using XAMPP. It's showing that the mail is send but i cannot see any mail. I am new to PHP.
HTML:
<form name='form' ng-app="" role="form" method="post" action="submit.php">
<div class="form-group col-sm-12">
<input type="text" ng-model="name" required name="name" maxlength="20" placeholder="Name" ng-pattern="/^[A-Za-z\s]+$/"/>
</div>
<div class="form-group col-sm-12">
<input type="text" name="email" required ng-model="email" placeholder="Email Address" ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/"/>
</div>
<div class="form-group col-sm-12">
<textarea type="text" ng-model="message" name="message" placeholder="Message"/></textarea>
</div>
<button type="submit" id="submit" value="Send" class="btn btn-primary" ng-disabled="form.$invalid">Send Message</button>
<div class="form-group col-sm-12 alert-danger">
<span class="error" ng-show="form.email.$error.pattern">ENTER A VALID EMAIL-ID</span>
<span class="error" ng-show="form.name.$error.pattern">ENTER A VALID NAME</span>
</div>
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'Demo Contact Form';
$to = 'myemail@hotmail.com';
$subject = 'Message from Contact Demo ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// If there are no errors, send the email
if (mail($to, $subject, $body, $from)) {
$result = '<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result = '<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
?>
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
I can see result on the output but no mail.
Configured few of the things under C:\xampp\sendmail\sendmail.ini
and C:\xampp\php\php.ini
These are the changes done.
sendmail.ini
smtp_server=localhost
php.ini
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = 127.0.0.1
smtp_port = 25
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesD:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
; sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"