Hi I am facing a problem with my contact form I didn't receive any mails and I don't know why ..
Here is my php code is there any thing wrong
<?php
$name=$_POST ['name'];
$mobileno=$_POST ['mobileno'];
$email=$_POST ['email'];
$message=$_POST ['message'];
$to = 'any mail.com';
$subject = ' Message from your Webite';
$msg = " Your name : $name\n";
$msg .= " Your Mobile No. : $mobileno\n";
$msg .= " Your email: $email\n" ;
$msg .= " Your Message: $message";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' Thank You <br/>';
echo ' Your name ' . $name . '<br>';
echo ' Your email ' . $email . '<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
?>
<br /><br />
Here is the result from $msg: <br /><br />
<?php
echo $msg;
?>
My HTML Code I have edited the code several times but nothing happened
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="justsend.php">
<p>
<label for="mobileno">your mobile</label>
<input type="text" name="mobileno" id="mobileno">
<label for="name"><br>
your name</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">your email</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="message">your message</label>
<textarea name="message" id="message" cols="45" rows="5"></textarea>
</p>
<p>
<label for="send">send msg</label>
<input type="submit" name="send" id="send" value="Submit">
</p>
</form>
</body>
</html>
$_POST ['name']; should be $_POST['name']; remove all the spaces in your post values.
so:
$name=$_POST ['name'];
$mobileno=$_POST ['mobileno'];
$email=$_POST ['email'];
$message=$_POST ['message'];
becomes:
$name=$_POST['name'];
$mobileno=$_POST['mobileno'];
$email=$_POST['email'];
$message=$_POST['message'];
and like EternalHour said, it might be a good idea to validate if the form is filled in somehow; try this just after you declared $name and $mobileno etc;
if(!empty($name) && !empty($mobileno) && !empty($email) && !empty($message)){
// do stuff
}
the reason you would use !empty() instead of isset() is because isset would still return true if the form is submitted, since the values are set.. they are just empty.
edit:
further in your HTML change action="get" to action="post" in order to get it working.
You need to fix your $_POST variables, but I would recommend this instead so you will know if your POST succeeded.
<?php
if (isset($_POST)) {
$name=$_POST['name'];
$mobileno=$_POST['mobileno'];
$email=$_POST['email'];
$message=$_POST['message'];
$to = 'any mail.com';
$subject = ' Message from your Webite';
$msg = " Your name : $name\n";
$msg .= " Your Mobile No. : $mobileno\n";
$msg .= " Your email: $email\n" ;
$msg .= " Your Message: $message";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' Thank You <br/>';
echo ' Your name ' . $name . '<br>';
echo ' Your email ' . $email . '<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
?>
<br /><br />
Here is the result from $msg: <br /><br />
<?php
echo $msg;
} else {
echo "submit failed!";
exit;
}
?>
This way you know if there is no message your form submitted properly.
First of all, if this is on a localhost, it wont work, cause mailfunction is disabled locally, you have to run it online
Further:
I dont see really where you are going wrong, but I took over my own mail function i got on my own website and converted it to yours
if(isset($_POST['send'])){ // checks if the data from the submit button with the name send is here
$name=mysqli_real_escape_string($con,$_POST['name']);
$mobileno=mysqli_real_escape_string($con,$_POST['mobileno']);
$email=mysqli_real_escape_string($con,$_POST['email']);
$message=mysqli_real_escape_string($con,$_POST['message']);
// you had spaces between your post variables which wont work. Also if you use mysqli, its better to play safe and make them safe, in case you do also database work. The variable $con is your connection information.
// echo out if your variables working. For example:
// echo $mobileno;
// this way you know for sure if the items are set.
$message = wordwrap($message, 70); // in case its a long message, this allows 70 characters on one line
$to = 'any mail.com'; // your email
$subject = ' Message from your Webite';
$msg = " Your name : ".$name."\n";
$msg .= " Your Mobile No. : ".$mobileno."\n";
$msg .= " Your email: ".$email."\n" ;
$msg .= " Your Message:".$message ;
$headers = "MIME-Version: 1.0" . "\r\n"; // this has to do with css and html in your msg
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // this has to do with css and html in your msg
$headers .= "From: noreply#yourwebsite.com"; // change this to whatever you want it to come from
if (mail ($to, $subject, $msg, $headers)) {
echo ' Thank You <br/>';
echo ' Your name ' . $name . '<br>';
echo ' Your email ' . $email . '<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
// to make sure if your email is send it will output your message as given above, else an error
}else{
echo ' Something went wrong ... oopsie daisy';
} // closure of the if mail check
} // closure of the complete if(isset) check
dont forget to include your connection info as well for the mysqli function to sanitize your variables in case you re going to add it as well to a database. Also it's just a good practise to do it anyway. I defined $con as the connection info, yours might be different. You have to change it then to your connection variable.
if you use mysql_ functions, use mysql_real_escape_string($_POST['YourPostVariable']); without the connection info. See here. http://php.net/manual/en/function.mysql-real-escape-string.php
--edit--
updated it, because your message wouldn't output your variables, just the $name instead of the name within the $name variable.
Hope this helps, good luck debugging :)
Hi I have just modified your code just a little bit..and I have recieved the email..please check with below code..please give your email in the textbox to recieve the email
<?php
if($_POST['email'] != '')
{
$name=$_POST['name'];
$mobileno=$_POST['mobileno'];
$email=$_POST['email'];
$message=$_POST['message'];
$to = $email;
$subject = 'Message from your Webite';
$msg = " Your name : $name\n";
$msg .= " Your Mobile No. : $mobileno\n";
$msg .= " Your email: $email\n" ;
$msg .= " Your Message: $message";
mail ($to, $subject, $msg, 'From:'.$email);
echo ' Thank You <br/>';
echo ' Your name ' . $name.'<br>';
echo ' Your email ' . $email .'<br>';
echo ' Your Mobile No. ' . $mobileno . '<br>';
echo ' Your Message ' . $message . '<br>';
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="justsend.php">
<p>
<label for="mobileno">your mobile</label>
<input type="text" name="mobileno" id="mobileno">
<label for="name"><br>
your name</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">your email</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="message">your message</label>
<textarea name="message" id="message" cols="45" rows="5"></textarea>
</p>
<p>
<label for="send">send msg</label>
<input type="submit" name="send" id="send" value="Submit">
</p>
</form>
</body>
</html>
Related
I have a problem that after I fill out the contact form on my HTML website I receive over 50 same E-mails. Its a HTML form connected to contact.php file which code is shown bellow. I have set everything but maybe there is a problem in my code or somewhere else.
My code is over here
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+ (ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Vyplnte meno.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Vyplnte email.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Zadali ste nesprávny e-mail, skúste to znovu.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Vyplnte text správy.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "noreply#marcelaskolenia.sk";
$address = "lubosmasura#gmail.com";
$toCustomer = $email;
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Mate novu spravu od ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "Mate novu spravu od $name." . PHP_EOL . PHP_EOL;
$e_content = "\"$subject\"" . "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "Kontaktujte $name cez email, $email alebo cez mobil $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers .= 'To: Test <noreply#marcelaskolenia.sk>' . "\r\n";
$headers .= 'From: Testk <noreply#marcelaskolenia.sk>' . "\r\n";
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3 class'mark'>Sprava bola odoslana.</h3>";
echo "<p>Dakujeme <strong>$name</strong>, Vasa sprava nam bude dorucena.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
HTML code
<div class="contact_form">
<div id="message"></div>
<form id="contactform" class="row" action="contact.php" name="contactform" method="post">
<div class="col-md-12">
<input type="text" name="name" id="name" class="form-control" placeholder="Meno">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
<input type="text" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo">
<input type="text" name="subject" id="subject" class="form-control" placeholder="Predmet">
<textarea class="form-control" name="comments" id="comments" rows="6" placeholder="Text správy"></textarea>
<button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ</button>
</div>
</form>
</div>
</div><!-- end col -->
Any Ideas why is this happening?
Thank you.
So I have some issues with my PHP Contactform on a HTML site.
Code below is what I have written in HTML. (that's not te problem)
<form action="sendmail.php" method="POST" class="contact-form">
<input type="text" placeholder="Amount" name="amount">
<input type="text" placeholder="Name" required name="name">
<input type="text" placeholder="Email Address" required name="email">
<div class="validation">
<button class="btn" name="submit">Send request</button>
// END HTML code. (BELOW is starts PHP).
$email_to = "domain#website.com";
$amount = $_POST["amount"];
$name = $_POST["name"];
$email = $_POST["email"];
$email_subject = "DOMAINNAME";
$headers = "From: " . $email . "\n";
$headers .= "Reply-To: " . $email . "\n";
$message = 'Name: ' . $name . ', email: ' . $email . ', amount: ' . $amount;
ini_set("sendmail", $email);
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false)
{$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email);}
{
header("Location:https://website.com");
} else {
echo "There has been an error sending your comments. Please try later.";
}
What do I wrong? I only wanna receive the --> name, amount and mail.
Only when I press submit on my HTML site, it's send me to website.com/sendmail.php (HTTP ERROR 500).
Thank you guys.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
HTML:
<form action="php/send-contact.php" class="contact-form" name="contact-form" method="post">
<div class="row">
<div class="col-sm-6 cols">
<input type="text" name="name" required="required" placeholder="Name*">
</div>
<div class="col-sm-6 cols">
<input type="email" name="email" required="required" placeholder="Email*">
</div>
<div class="col-sm-6 cols">
<input type="text" name="subject" required="required" placeholder="Subject*">
</div>
<div class="col-sm-12 cols">
<textarea name="message" required="required" cols="30" rows="5" placeholder="Message*"></textarea>
</div>
<div class="col-sm-12 cols">
<input type="submit" name="submit" value="Send Message" class="btn btn-send">
</div>
</div>
</form>
php/send-contact.php:
<?php
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'hello#domain.co.uk';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $body, 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message);
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<script>
alert("Thank you for getting in touch. We will contact you as soon as possible.");
</script>
<meta HTTP-EQUIV="REFRESH" content="0; url=../index.html">
</head>
The HTML alert activates and refreshes as it should, but it doesnt send any email...
I have tried numerous email address recipients.
Also, are there any special measures I should take into account (regarding the PHP elements) when adding Google ReCaptcha to this form?
So I have tested this, and I think it is doing what you want.
$name = htmlentities($_POST['name']);
$email_from = htmlentities($_POST['email']);
$subject = htmlentities($_POST['subject']);
$message = htmlentities($_POST['message']);
$email_to = 'Admin#Domain.com';//replace with your email
$headers = "From: webmaster#example.com" . "\r\n" . "CC: ". $email_from; //This adds a from field, as well as CC's the person submitting the request.
//Build the body of the eamil
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email_from . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'message: ' . $message;
$success = mail($email_to, "Contact from site X, regarding: ".$subject, $body,$headers);
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<?php if($success){ //If the email was sent correctly?>
<script>
alert("Thank you for getting in touch. We will contact you as soon as possible.");
</script>
<?php header('Location: ../index.html'); }else{?>
<script>
alert("There was an error when sending the email, please try again later.");
</script>
<?php header('Location: ../index.html'); } //If the email falied?>
</head>
The other file (the html) remains the same. Simply replace your code in php/send-contact.php with this.
This php contact form I'm using returns the message that my message has be sent but no email is received by the specified email address.
Here's the php:
<?php
$to = 'blahbahblah#gmail.com';
if($to) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$html = "";
$html .= "Name: " . htmlentities($name, ENT_QUOTES, "UTF-8") . "<br>\n";
$html .= "Email: " . htmlentities($email, ENT_QUOTES, "UTF-8") . "<br>\n";
$html .= "Message: " . htmlentities($message, ENT_QUOTES, "UTF-8") . "<br>\n";
$headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n";
$headers .= "From: " . $name . "<". $email .">\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$html = utf8_decode($html);
mail($to, $subject, $html, $headers);
if ($html)
echo 'ok';
else
echo 'error';
} else {
echo "error";
}
?>
And here's the html associated with it:
<form method="post" action="contact.php">
<p>
<input type="text" name="name" id="name" placeholder="Name" />
</p>
<p>
<input type="text" name="email" id="email" placeholder="Email" />
</p>
<p>
<input type="text" name="subject" id="subject" placeholder="Subject" />
</p>
<div class="textarea-wrapper">
<textarea name="message" id="message" cols="45" rows="10" placeholder="Message"></textarea>
</div>
<button id="submit">Send</button>
</form>
I realize issues like these are frequent, but I've unable to figure it out. Any insight is greatly appreciated.
"<br>\n"
use "\r\n" instead and try again
You need to change your SMTP settings per your conversation with the support rep. These are set in your PHP.INI
The From address should belong to the domain from where you are running the script. If your script is running on your-website.com then the From address should be like xyz#website-name.com
$headers = "From: xyz#website-name.com";
mail($to,$subj,$body,$headers);
To check the contact form that I have used, visit: http://manageproac.com/support/
I m having a problem with my email php form, when I click in the submit button an other page shows up saying There was a problem with your e-mail ()
I don't no what I am doing wrong?
here is my code:
html code
<!-- Subscription Form -->
<form class="email" action="form.php" method="post">
<input class="get_notified" type="text" placeholder="Enter your email address ..."/>
<button type="submit" class="go" /></form>
<!-- End Subscription Form -->
</div>
</div>
</body>
php code
<?php
$to = "email#mydomain.com";
$from = "email#mydomain.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
You'll need to add a name="email" field to your HTML form in order for PHP to be able to fetch it using $_POST['email']
<input class="get_notified" name="email" type="text" placeholder="Enter your email address ..."/>