<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: yoursite.com';
$to = 'contact@yoursite.com';
$subject = 'Customer Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
I've tried creating a simple mail form. The form itself is on my index.html
page, but submits to a separate "thank you for your submission" page, thankyou.php
, where the above PHP code is embedded.
The code submits perfectly, but never sends an email. please help.
If you are running this code on a local server (i.e your computer for development purposes) it wont send the email to the recipient. What will happen is, it will create a
.txt
file in a folder namedmailoutput
.In the case if you are using a free hosing service like
000webhost
orhostinger
, those service providers disable themail()
function to prevent unintended uses of email spoofing, spamming etc. I prefer you to contact them to see whether they support this feature.If you are sure that the service provider supports the mail() function, you can check this PHP manual for further reference, PHP mail()
To check weather your hosting service support the mail() function, try running this code, (Remember to change the recipient email address)
Hope this helped.
You can use config email by codeigniter, example using smtp (simple way) :
It's works for me!