PHP Ccontact form [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 2 years ago.
I'm trying to get this PHP form to work, every time I submit the form the browser returns the else statement but doesn't execute the above if statement, what have I missed?
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mail = $_POST['mail'];
$message = $_POST['message'];
$to = '***.*****#gmail.com';
$subject='Form submission';
$message="Name: ".$name."\n". "Wrote the following: "."\n\n".$message;
$headers="From: ".$mail;
if (mail($to, $subject, $message, $headers)) {
echo "<h1>Sent Successfully! Thank you"." ".$name.", I will contact you shortly.</h1>";
}
else {
echo "Something went wrong! Contact me at alec.dannmayr#gmail.com";
}
}
?>
<input type="text" name="name" placeholder="Full Name">
<input type="text" name="mail " placeholder="Email">
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Message" cols="30" rows="10"></textarea>
<input type="submit" name="submit"></input>
</form>

There is something wrong with your mail() function.
Try looking in your maillog if anything is triggered at all. Usually located under /var/log/mail.log or /var/log/mail.err depending on your configuration. Have you tried sending the mail without the header (just to minimise possible errors).
It can be a pain to configure the mail() function to work properly. See this article, it might give you a hint. Is there a reason you want to use the mail() function a more advanced technique? You could use f.e. https://github.com/PHPMailer/PHPMailer which supports a better error/debugging management.

Related

How to fix this php file for sending email

i have created this php form for enquiry purpose but when i clicked on the submit button it's not working. can you tell me what have i done wrong in this code.
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type ="text" name="subject" placeholder="subject">
<input type ="email" name="email" placeholder="email">
<textarea rows="5" name="message" cols="30"></textarea>
<input class="btn" type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit'])){
$to = "rizwandesigns19#gmail.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['email'];
$headers = "From : $from";
mail($to, $subject, $message, $headers);
}
echo "Mail Sent";
?>
or can you give me valid php script for this purpose.
To get through google's and other's spam filters you need an address which the mail is sent from. For this you could create a new Gmail-address and use the phpmailer-library.
Edit: Setup with gmail is actually pretty complicated and it will disable your access once in a while which renders it almost unuseable. I started to do it by installing a real mail server on the host machine (Install a Complete Mail Server with Postfix and Webmail in Debian 9) and use the php mail() function (phpmailer can still be used tho).

My web form is not linking to my email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
How can I send an email using PHP?
(20 answers)
Closed 6 years ago.
I am trying to create a web form for a website, but when I hit send, the page links to the .php file. Please tell me what I am doing wrong.
The .html and .php codes respectively look like this:
<form action="email.php" method="post">
<input class="input-text animated wow flipInY delay-02s" type="text" name="name" value="Your Name *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
<input class="input-text animated wow flipInY delay-04s" type="text" name="email" value="Your E-mail *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
<textarea class="input-text text-area animated wow flipInY delay-06s" name"description" cols="0" rows="0" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">Describe your facilities and what you’re looking for. *</textarea>
<input class="input-btn animated wow flipInY delay-08s" type="submit" value="send message">
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$description = $_POST['description'];
$to = "Email Address";
$subject = "Facility and Other Specifications";
mail($to, $subject, $description "From: " . $name);
echo "Your message has been sent.";
?>
Also, I am not certain how to use PHP with the .php and .html files, or whether or not the operating system I am using (Snow Leopard) already comes with it.
I'm a little new to all of this, and any bit of information will be greatly appreciated.
If you mean what I think you do, it's linking to the literal code of your PHP file. From that, I can tell you that you probably don't have PHP installed. Thus, you need to install it.
Be sure your php code is in a separate document (email.php).
Extra: Change
mail ($to, $subject, $description "From: " . $name);
echo "Your message has been sent.";
to
$success = mail($to, $subject, $description "From: " . $name)
if($success){
echo "Your message has been sent.";
}else{
echo "Mail failure";
}
Right now your code is saying success even on a failure. The mail function returns true on success so you can just check the variable to see if it worked

mail() function not working in php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I've looked everywhere on the web and I can't find a solution to my mail function. I've used xampp localhost and ive uploaded to a domain with no results.
My PHP code is:
<?php
//Grab from html form
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$error = "";
//check if fields are filled
if (empty($subject)) {
$error = "Enter a subject";
}
if (empty($message)) {
$error .= "Enter a message";
}
echo $error;
//send email
mail($email, $subject, $message);
?>
The html code is below just in case...
<!DOCTYPE HTML>
<html>
<head>
<meta charset= "utf-8">
</head>
<body>
<form action="serverCode/mail.php" method="post">
Subject: <input type="text" name="subject"><br>
From: <input type="text" name="from"><br>
From Email: <input type="text" name="fromEmail"><br>
Message: <input type="text" name="message"><br>
To Email: <input type="text" name="email"
<input type="submit" value="Submit">
</form>
</body>
</html>
I'm just trying to make a simple webmailer in PHP.
It's probably due to a bad PHP configuration (specially if you are running XAMPP on Windows) or missing email headers. That was already asked many times. Check these links:
How to send an email using PHP?
php mail setup in xampp
Your HTML markup is incorrect:
The <input> element with the name "email" does not have a closing tag:
To Email: <input type="text" name="email"

PHP contact form returns successful, but doesn't send anything [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I'm working on a personal portfolio website (www.corybolles.com) and I'm attempting to create a contact from based off of PHP. I have very little knowledge of PHP compared to HTML and CSS, and I was wondering if anyone could help me figure out why this is not working correctly.
HTML
<div id="contact">
<form action="contact.php" method="post">
<label>Name</label><br>
<input class="forminput" type="text" name="cf_name" width="50px"><br>
<label>Email</label><br>
<input class="forminput" type="text" name="cf_email" width="50px"><br>
<label>Message</label><br>
<textarea class="forminput" name="cf_message" cols="18" rows="10"></textarea><br>
<input class="formbutton" type="submit" name="submit"value="Send">
<input class="formbutton" type="reset" name="clear" value="Clear">
</form>
</div>
PHP
<?php
$name = $_POST['cf_name'];
$email = $_POST['cf_email'];
$message = $_POST['cf_message'];
$from = 'From: www.corybolles.com';
$to = 'jcbollesjr#gmail.com';
$subject = 'Message from user via www.corybolles.com';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thanks! Your message has been sent!</p>';
} else {
echo '<p>Sorry, something appears to have broken. Please try again</p>';
}
}
?>
You can test it yourself, but whenever I fill out the form to test it, it returns a successful message, however doesn't actually send anything.
Try this in a seperate file to check if mail is actually 'working', as your current code looks fine.
<?php
echo mail('your#address.com', 'your#address.com', 'test');
?>
This script tries to send an email to your#address.com, from your#address.com, and echoes the return value of the function. If it doesn't echo 'TRUE' or '1', there is a weird problem. If it does, and you don't receive any mails in your mailbox, you should contact your server administrator.
It may be your server. If you don't own it, contact your system administrator. Possible causes could be: closed ports, packet filtering or security systems (such as SELinux) in your server or within the local network.
Look into PHPMailer which allows you to send mail via SMTP. This will mean that you have a store of all the emails that have been sent out, and will lower the risk of your mail being sent into user's spam folders!

My HTML contact form to PHP mail isn't working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have a decent understanding of HTML and CSS but completely novice when it comes to PHP. I've scouted the net and tried this out with multiple different tutorials, however I can't seem to tailor the php code to work with my contact page's email form. (www.richseeley.com/contact)
Ultimately, I would like this form to confirm the message being sent with a pop up window, without leaving the page, but so far I can't even get it to work in the most basic sense.
At present, it is echoing the "thank you for using our mail form", however the email isn't sending.
Here is the html coding for my contact form:
<div id="form-main">
<div id="form-div">
<form class="form" id="form1" action="scripts/test.php" method="post" enctype="text/plain">
<input name="name" type="text" class="feedback-input" placeholder="Name" id="name" />
<input name="email" type="text" class="feedback-input" id="email" placeholder="Email" />
<textarea name="message" class="feedback-input" id="message" placeholder="Message"></textarea>
<input type="submit" value="SEND" id="button-blue"/>
</form>
</div>
</div>
And here is the PHP code that I have most recently been trying to work with:
<?php
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("r*******#gmail.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
?>
I appreciate that this is a fairly simple problem I am trying to solve, but I've spent several hours with no success, and I really don't want to have to compromise the design of my work/website, and end up using something less stylised, as a basic tutorial would provide.
The only way I could think of doing it would be something like:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
echo <p>Are you sure you want to do this?</p>
<form action="send_mail.php" method="post">
<input type="submit" name="ok" value="OK" />
<input type="submit" name="cancel" value="Cancel" />
</form>
?>
and in send_mail.php:
<?php>
//send email
if (isset($_POST['ok'])) {
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("richsee******#****.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
}
if (isset($_POST['cancel'])) {
header('Location: didnt_confirm.html");
}
?>
Also, your php seems wrong and vulnerable, but all you're asking is for a confirmation ;)
If you're concerned about vulnerability (header injections), you can read this.

Categories