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
Related
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).
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.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I have a registration form that requires Name, Phone, and and an optional comments section. After running multiple tests, the form seems to submit and (the bottom of the php code) the page redirects me to the "thank you page". But I don't get an email whatsoever. Anyone know what I'm doing wrong?
<form class="register-form" name="registerform" method="post" action="form-to-email.php">
<div class="form-column">
<p>Fields marked with * are required.</p>
<label for="first_name">First Name *</label>
<input type="text" id="first_name" name="first_name" placeholder="John">
<label for="last_name">Last Name *</label>
<input type="text" id="last_name" name="last_name" placeholder="Smith">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="503 999 9999">
<label for="comments">Comments</label>
<textarea id="comments" name="comments"></textarea>
</div><!--/ Form Column -->
<div class="submit-wrap"><input class="submit-form" type="submit" value="Register" /></div>
</form><!--/ Form -->
The PHP looks like this:
<?php
$myemail = 'veeeeeech#gmail.com';
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$visitor_phone = $_POST['phone'];
$comments = $_POST['comments'];
$to = $myemail;
$email_subject = "$first_name\n $last_name\n registered for Winter Camp 2015";
$email_body = "They said: \n $comments". "Their phone number is $visitor_phone.\n".
$headers = "From: $myemail\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: registered-thanks.html');
?>
Mail delivery is an inexact science from the programmer's POV. The system admin has a bit more control over it ... are you also the "box owner"?
You're not even checking to see if the mail() call failed:
$success = mail($to,$email_subject,$email_body,$headers);
if ($success) header('Location: registered-thanks.html');
else die("Could not send mail!!");
Of course that is way simplified ... better error handling would be a nice start.
Assuming that ($success) is returning true, it's then up to the system to do the right thing. Questions you'll need to ask include: is my PHP installation properly set up to do mail() ?
Does my web host allow it?
Is there a firewall blocking outbound SMTP connections?
What do the server logs say?
Did the mail get caught in a spam filter?
You can see why I say "an inexact science"....
PHP's mail function will return true when the message has been accepted for delivery. This is different from actually delivering or guaranteeing delivery, as noted by Kkinsey.
If you have shell access to the server where your web files are hosted you can test out whether or not you can even send mail out by trying this.
mail -s "Test Email" veeeeeech#gmail.com
Enter a line of text, then on a line all by itself enter a single "." and hit return. Look for the mail in your gmail account.
You might also try using sendmail directly as a quick test.
sendmail veeeeeech#gmail.com
have you checked the spam folder? some services will reject the email if it doesnt have a reply-to header.
$myemail = 'veeeeeech#gmail.com';
$to = $myemail;
$headers = "From: $myemail \r\n";
$headers .= "Reply-To: $myemail \r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$success = mail($to,$email_subject,$email_body,$headers);
if ($success) header('Location: registered-thanks.html');
else die("Foobar. Your mom.");
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!
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.