I am attempting to send an email by filling out a contact form. Both my html form and php file are included below. Once I fill out the form, it notifies me that the email has been sent. However, I never receive an email; I cannot figure out what i am doing wrong.
This is my html form:
<div class="row" style="padding-top:27px">
<div class="large-6 column">
<form action="mail.php" method="POST" data-abide>
<div class="name-field">
<label>Your name*</label>
<input type="text" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
</div>
<div class="large-6 column">
<!-- <label> Message </label>
<textarea class="error" placeholder="Message..." id="info" class="message" name="message" cols="70" rows="60" size="90" requi></textarea><br>-->
<label> Message </label>
<textarea class="error" placeholder="Message..." ></textarea>
<small class="error">Invalid entry</small>
<div>
<input style="float:right;" type="submit" value="Submit">
<img style="visibility: hidden;">
</div>
</form>
This is my php file:
<?php
$to = "education#arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
UPDATED FILES:
HTML:
<div class="name-field">
<label>Your name*</label>
<input type="text" name="name" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" name="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" name="subject" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
<!-- End Contact Form -->
</div>
PHP:
<?php
$to = "education#arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
None of your input fields have a name associated with them, so you're likely getting empty data in your POST. The 'email' value within $_POST['email'] refers to an input field's name.
Specifically, you're not getting an email address from your form, so the email is not sending to anyone.
For instance, you'll need:
<input type="email" name="email" required>
The fourth parameter of mail() is additional headers. Which is where your "FROM" information should go.
Refer here:
http://php.net/manual/en/function.mail.php
for what should go there.
here's one example
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Related
I hosted my website through Hostinger. I inserted a PHP form on my website to send an email using my mail id. But when I am testing this feature on domainname.com/contactform.php, system show blank screen instead of running the code. I tried to solve my issue but I can not find my mistake. Please Help!
<div class="col-md-6 padding">
<!-- banner form -->
<form action="contactform.php" method="post">
<h5 class="mb-3">Register Here</h5>
<div class="form-style-w3ls">
<input placeholder="Your Name" name="name" type="text" required="">
<input placeholder="Your Email Id" name="email" type="email" required="">
<input placeholder="Contact Number" name="number" type="text" required="">
<select>
<option value="0">Business Type</option>
<option value="1">Corporate</option>
<option value="1">Partnership</option>
<option value="1">Other</option>
</select>
<!--<input placeholder="Password" name="password" type="password" required=""> -->
<button Class="btn" name="submit"> Submit</button>
<span>By Registering, You agree to Our Terms & Conditions.</span>
</div>
</form>
PHP Form
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$MailFrom = $_POST['email'];
$contactnumber = $_POST['number'];
$Businesstype = $_POST['type'];
$mailTo = "care#thecraftedu.com";
$headers = "From: ".$MailFrom;
$txt = "You have received an Email from ".$name.".\n\n".$contactnumber;
mail($mailTo, $txt, $headers);
header("Location: index.php?mailsend");
}
?>
I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">
I have a problem. Today I made contact form but it is not sending any emails and I don't know why. I downloaded an free example and I tried to add it to my own site but it's not working, any ideas? Here is the code:
<form id="contact-form" class="wniosek" action="wyslijWniosek.php" method="POST">
<div class="col-sm-4">
<label class="firma rel col-sm-12"><span class="inp"><input name="firma" type="text" placeholder="Nazwa Firmy" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="name rel col-sm-12"><span class="inp"><input name="name" type="text" placeholder="Imie i nazwisko" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="phone rel col-sm-12"><span class="inp"><input name="phone" type="text" placeholder="Telefon" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="email rel col-sm-12"><span class="inp"><input name="email" type="text" placeholder="E-mail" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="kwota rel col-sm-12"><span class="inp"><input name="kwota" type="text" placeholder="Prognozowana Kwota" class="col-sm-12"></span></label>
</div>
<div class="col-sm-4">
<label class="wnio col-sm-12">
<select name="wnio" style="width:100%;">
<option value="kfirm">Kredyt Firmowy</option>
<option value="kgot">Kredyt Gotówkowy</option>
<option value="kobro">Kredyt Obrotowy</option>
<option value="phipo">Pozyczka Hipoteczna</option>
<option value="khipo">Kredyt Hipoteczny</option>
<option value="kkonso">Kredyt Konsolidacyjny</option>
<option value="kinwest">Kredyt Inwestycyjny</option>
<option value="ksamocho">Kredyt Samochodowy</option>
<option value="leasing">Leasing</option>
</select>
</label>
</div>
<div class="col-sm-12">
<label class="message rel col-sm-12"><span class="text_a"><textarea name="message" class="col-sm-12" placeholder="Wiadomosc" style="height:300px;"></textarea></span></label>
</div>
<div class="col-sm-4">
<div class="buttons-wrapper">
<input class="button2 btn btn-white" type="submit" value="Send">
<input class="button2 btn btn-white" type="reset" value="Clear">
</div>
</div>
</form>
and php:
<?php
$firma = $_POST['firma'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$wnio = $_POST['wnio'];
$kwota = $_POST['kwota'];
$message = $_POST['message'];
$formcontent=" Nazwa Firmy: $firma \n Imie i Nazwisko: $name \n Email: $email \n Telefon: $phone \n Wniosek: $wnio \n Prognozowana Kwota: $kwota \n Wiadomość: $message";
$recipient = "<mail here>";
$subject = "Formularz Kontaktowy";
$mailheader = "Wiadomość ze strony internetowej";
mail($recipient, $subject, $formcontent, $mailheader) or die("Błąd!");
echo "Dziękujemy!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
where is mail here i put my own email
Please replace mail($recipient, $subject, $formcontent, $mailheader) or die("Błąd!"); with below code.
$suc = mail($recipient, $subject, $formcontent, $mailheader);
if($suc){//If success
print_r("No error");
}
else{//If error on mail send
print_r(error_get_last());
}
exit();//Remove this after debugging done
If mail() not delivered successfully this code will print error into array format, else it would print 'No error'.
Let us know if you face any further query regarding the same.
You have to set the sender e-mail in your header.
$mailheader = "From: sender#mail.com";
I have a form on my site. When the user submits the form I get the email response but there is no form data returned. All I see is
Company:
Name:
Email:
Phone:
The form html is below:
<form method="post" action="send_survey.php" class="survey" >
<header><img src="../img/PTS_Survey_logo.jpg" alt="Patterson Tubular Services Logo">
Customer Survey</header>
<fieldset>
<section>
<label class="input">
<i class="icon-append icon-group"></i>
<input type="company" id="company" required placeholder="Company name">
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-user"></i>
<input type="name" id="name" required placeholder="Your name" >
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-envelope-alt"></i>
<input type="email" id="email" required placeholder="Your e-mail">
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-phone"></i>
<input type="phone" id="phone" placeholder="Your phone number">
</label>
</section>
</fieldset>
<footer>
<input id="submit" name="submit" type="submit" value="submit" class="button">Submit the survey</button>
</footer>
</form>
The php code is below:
<?php
/*Subject and email variables */
$emailSubject = 'PTS Site Test';
$emailTo = 'testemail#testemail.com';
/* Gather form information */
$company = $_POST['company'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail ($emailTo, $emailSubject, $body, $headers);
/* Results rendered */
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=http://www.cudd.com/PTS-2014/index.html">';
?>
Thank you in advance.
HTML form input is set in POST by the element's name attribute, not its id. You should set the name attribute to the same as the id on each of your input elements.
You have no name attribute on any of your inputs
Change:
<input type="company" id="company" required placeholder="Company name">
To:
<input type="company" name="company" id="company" required placeholder="Company name">
i'm getting blank field returns in my inbox on only a portion on my form fields
like so:
From: whatevername
Email: fgsdfg#fakeysite.com
Message:
phone:
here is my code its probably something really dumb but its bugging me, so here we go.
HTML
<div class="row-item col-1_4">
<h3>Contact Form</h3>
<h4>Please fill out the form to get your free CD Replacement Kit</h4>
<!-- Success Message -->
<div class="form-message"></div>
<!-- Form -->
<form class="b-form b-contact-form" action="blast.php">
<div class="input-wrap m-full-width">
<i class="icon-user"></i>
Name
<input class="field-name" type="text" placeholder="Name (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-phone"></i>
Phone
<input class="field-phone" type="text" placeholder="Phone">
</div>
<div class="input-wrap m-full-width">
<i class="icon-envelope"></i>
Email
<input class="field-email" type="text" placeholder="E-mail (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-pencil"></i>
Message
<input class="field-comments" type="text" placeholder="Message">
</div>
<input class="btn-submit btn colored" type="submit" value="Send">
</form>
PHP
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient = "csmith#legacybrokerage.com";
$subject = "UNLIMITED ANNUITY LEADS CD BLAST";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
try this, define name= 'something' to the input field
<input class="field-name" type="text" placeholder="Name (required)" name="name">
<input class="field-phone" type="text" placeholder="Phone" name="phone">
<input class="field-email" type="text" placeholder="E-mail (required)" name="email">
your input's dose not name attribute!
<input class="field-name" type="text" placeholder="Name (required)">
correct :
<input name="from" class="field-name" type="text" placeholder="Name (required)">