0

I am using following script to send contact us form details through email from my website.

But script is not working, getting Error sending mail message.

Not getting what is the problem here:

<?php 
$MailToAddress = "ToEmailID"; 
$redirectURL = "index.html"; 
$MailSubject = "Inquiries - Contact Us"; 
$redirectURL = "index.html";
$message_body = "NAME: ".$_POST["name"]."\r\n"; 
$message_body .= "E-Mail: ".$_POST["email"]."\r\n";
$message_body .= "SUBJECT: ".$_POST["subject"]."\r\n";
$message_body .= "MESSAGE: ".$_POST["message"]."\r\n";

if (!mail($MailToAddress, $MailSubject, $message_body)) {
    echo "Error sending e-mail!";
}
else {
    header("Location: ".$redirectURL);
}     
?> 

And here is the form:

<form action="submit.php" class="contact-form" method="post">
    <div class="col-md-4"><input id="senderName" name="name" placeholder="name" type="text" /></div>
    <input id="senderEmail" name="email" placeholder="email address" type="text" />
    <input id="subject" name="subject" placeholder="subject" type="text" />
    <textarea id="message" name="message" placeholder="Message" required="" rows="6"></textarea>
    <input class="btn-regular alignleft contact_button" type="submit" value="SUBMIT" name="submit">
</form>
devpro
  • 16,184
  • 3
  • 27
  • 38
user3368088
  • 151
  • 2
  • 15
  • Do you have an MTA installed such as `sendmail`? – Jonnix Sep 30 '16 at 16:42
  • Possible duplicate of [PHP mail not working for some reason](http://stackoverflow.com/questions/8803994/php-mail-not-working-for-some-reason) – devpro Sep 30 '16 at 16:46
  • @JonStirling: how i can check it? – user3368088 Sep 30 '16 at 16:46
  • anything from http://php.net/manual/en/function.error-reporting.php ? and you running as local or hosted? any JS involved also? – Funk Forty Niner Sep 30 '16 at 16:47
  • @Fred-ii-: No, am not running it on local, its on hosted, no JS involved – user3368088 Sep 30 '16 at 16:48
  • I too have edited my comment – user3368088 Sep 30 '16 at 16:53
  • is mail made available for you to use? I've seen cases where it would fail silently on (free) hosted sites; if you're on a free one that is. Hard to say what the issue could be besides that. Contact their tech support. You can try phpmailer also and make sure you use the right headers. Mail will fail if a `From: ` is omitted. Consult the manual http://php.net/manual/en/function.mail.php – Funk Forty Niner Sep 30 '16 at 16:55

0 Answers0