No input file specified when sending email php - php

UPDATE: non of any php files is running. Is there a way to solve the problem ?
I have html a page that takes the email details:
<form method="POST" sourceindex="44" action="semail.php" name="form1" onSubmit="return validate_form ( );">
<p>
<label>Your name:<br>
<input sourceindex="47" name="mail_name" class="text_field" type="text">
</label>
</p>
<p>
<label>Your e-mail:<br>
<input sourceindex="51" name="mail_email"
class="text_field" type="text">
</label>
</p>
<p>
<label>Message:<br>
<textarea sourceindex="55" name="mail_msg" cols="45"
rows="5" class="text_area"></textarea>
</label>
</p>
<input name="B1" type="submit" class="form_button" value="" />
</form>
and here is the php code (this is all in semail.php):
<?php
$mail_to ="someEmail#hotmail.com";
$mail_subject = "Message From a Customer";
$mail_body ="Name of the Coustomer: ".$_POST['mail_name']."\n";
$mail_body .= "E-Mail Of the Coustomer: ".$_POST['mail_email']."\n";
$mail_body .= "The Message: ".$_POST['mail_msg']."\n";
if(mail($mail_to, $mail_subject, $mail_body))
echo "Thanks for your Message";
else
echo "Failed to send the e-mail"
?>
Whenever I click send the semail.php page shows me this error: No input file specified
Can someone help me please in figuring out where is the problem ?

To first check and verify that PHP is running and available with the present Web hosting company, create a file called check_server.php and insert the following code:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
If successful, you will see your server information and configurations. It will also show the path to mail.
Regarding your form code:
My answer may or may not solve a probable Hosting company issue, however there were a few errors in your code which would result as unsuccessful.
Please read the following:
In using the following form, had success in sending and receiving the message.
<form method="POST" sourceindex="44" action="semail.php" name="form1">
<p>
<label>Your name:<br>
<input sourceindex="47" name="mail_name" class="text_field" type="text">
</label>
</p>
<p>
<label>Your e-mail:<br>
<input sourceindex="51" name="mail_email"
class="text_field" type="text">
</label>
</p>
<p>
<label>Message:<br>
<textarea sourceindex="55" name="mail_msg" cols="45"
rows="5" class="text_area"></textarea>
</label>
</p>
<input name="B1" type="submit" class="form_button" value="Submit" />
</form>
N.B.: I do need to point out that your PHP mail handler did not contain a few required elements.
For example the From: element/variable which was not present in your handler.
$mail_email= $_POST['mail_email'];
Also headers were not present. Mail requires 4 variables to send/receive Email.
For example you have if(mail($mail_to, $mail_subject, $mail_body))
Which should read as if(mail($mail_to, $mail_subject, $mail_body, $headers))
Omitting the headers would result in a message marked as SPAM because of the missing Email from and would show as unknown sender
In conjunction with the form above, am including a working copy of the PHP mail handler:
<?php
$mail_to ="someEmail#hotmail.com";
$mail_email= $_POST['mail_email'];
$mail_subject = "Message From a Customer";
$mail_body ="Name of the Customer: ".$_POST['mail_name']."\n";
$mail_body .= "E-Mail Of the Coustomer: ".$_POST['mail_email']."\n";
$mail_body .= "The Message: ".$_POST['mail_msg']."\n";
$headers = "From: $mail_email \r\n";
$headers .= "Reply-To: $mail_email \r\n";
if(mail($mail_to, $mail_subject, $mail_body, $headers))
echo "Thanks for your Message";
else
echo "Failed to send the e-mail";
?>
Read up on the mail( ) function on PHP.net: http://php.net/manual/en/function.mail.php

Related

Trying to send an email with PHP from HTML form resulting in an HTTP Error 405

So I wanted to make a contact form for a website that can actually send emails, but ended up with this error :
Here's my html code:
<div class="contact-fast">
<div class="contact-form">
<form id="contact-form" method="POST" action="contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your Name" required> <br>
<input name="email" type="email" class="form-control" placeholder="Your Email" required> <br>
<textarea name="message" class="form-control" placeholder="Message" rows="8" required></textarea> <br>
<input type="submit" class="form-control submit" value="SEND MESSAGE">
</form>
</div>
</div>
And here's my PHP code:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'skeremobiel#gmail.com';
$email_subject = 'New Mail From Website';
$email_body = "Username: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "said444b#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
if ($visitor_email!=NULL) {
mail($to,$email_subject,$email_body,$headers);
}
header("Location: http://127.0.0.1:5500/social.html");
die()
?>
Here's how my page looks like before and after submitting the form:
I think the problem is that when i click on the submit button i get directed to 127.0.0.1:5500/contact-form-handler.php (as you can see in the last image in my question). It doesn't execute the php file, but it just opens it.
Any help would be appreciated!
Many things can go wrong.
Make shure php error reporting is on. Google for that.
Try to find where the error code is coming from by reducing your problem.
For instance, comment out mail() and see if it works.
Or replace your php code by a simple text to see if the code runs, if the text appears on your browser screen.
Or Google for error 405. You will learn it is an http error, something in the data exchange between your browser and the server.
Do you have characters before <?php because if you have, the server will not be able to output the HTTP header any more.
Is your php file located at the webserver root and called contact-form-handler.php?

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).

Forms - PHP within HTML page, data not getting emailed

I am using PHP to send data to an email address from a HTML form. It worked fine while the PHP file was a pure PHP file, displaying the confirmation text upon submitting the form. However, I needed the confirmation text to appear within our usual templates so I added the same PHP into the body of a page and set the form action to go to that page. When someone now submits the form, an email does get sent but it contains none of the information from the form. Can you help?
HTML:
<form method="post" action="thank-you-page.html">
Email: <input name="email" type="text"><br />
Name: <input name="name" type="text"><br />
<h3>Your message</h3>
Subject: <input name="subject" type="text"><br />
Message:<br /> <textarea name="message" rows="15" cols="40"></textarea><br />
<input type="submit" />
</form>
PHP within body of thank-you-page.html:
<?php
$to = "myemail#email.com";
$subject = 'Feedback from online form';
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print 'Your mail was sent successfully. Thank you for your feedback.'; }
else
{print 'We encountered an error sending your mail.'; }
?>
Thank you!
Your thank you page needs to be a PHP page, not just an HTML page.
Change it to be thank-you-page.php

Javascript Form Submit with Email Action?

I need make this form send me a email like a contact form:
Script code:
<script type="text/javascript">
$(document).ready(function(){
$("#contactLink").click(function(){
if ($("#contactForm").is(":hidden")){
$("#contactForm").slideDown("slow");
}
else{
$("#contactForm").slideUp("slow");
}
});
});
function closeForm(){
$("#messageSent").show("slow");
setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
}
</script>
HTML CODE:
<div class="box">
<div id="contactFormContainer">
<div id="contactForm">
<fieldset>
<label for="Name">Nome: </label>
<input id="name" type="text" />
<label for="Telefone">Telefone Fixo: </label>
<input type="text" id="phone" maxlength="15" onkeypress="Mascara(this);" />
<label for="Message">Assunto:</label>
<textarea id="Message" rows="3" cols="20"></textarea>
<input id="sendMail" type="submit" name="submit" onclick="closeForm()" />
<span id="messageSent">Sua solicitação foi enviada com sucesso, por favor, aguarde...</span>
</fieldset>
</div>
<div id="contactLink"></div>
</div>
When click and close the form i need send me a email with the content of form, how to?
Some idea? thanks!
Firstly i can't see the form tags in your code. According to me you're doing this wrong and i'm sure many of our friends on stack will agree too.
Your question suggests that you basically want to receive an email with the data submitted through the form. Why don't you try the below method.
HTML
<form action="mail.php" method="POST">
<input type="text" name="fname"></input>
<input type="text" name="lname"></input>
<button>SUBMIT</button>
</form>
PHP
<?php
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$to = "someone#example.com";
$subject = "Hello World";
$message = "Firstname: $firstname \n\n Lastname: $lastname";
$from = "sender#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
The above example is the most simplest method of sending an email. You can go advance by adding more header information and graphically formatting the email.
Go through these tutorials if you get confused.
http://www.w3schools.com/php/php_mail.asp
http://www.phpeasystep.com/phptu/8.html
And since you mentioned that you want to perform the task via javascript you can try submitting the form via ajax, refer the below tutorials
http://teachingyou.net/php/simple-php-contact-form-using-ajax/
http://www.sitepoint.com/forums/showthread.php?1055068-Send-PHP-email-using-jQuery-AJAX
Since you've tagged the question php, have a look at php's mail function. http://php.net/manual/en/function.mail.php
$to = 'you#domain.com';
$subject = 'Contact Form';
$message = '...' //concatenate the $_POST (or $_GET) variables to create this message
mail($to, $subject, wordwrap($message, 70, "\r\n");
This function requires that your server has a properly configured to send mail - see the php documentation for requirements: http://www.php.net/manual/en/mail.requirements.php

code won't populate email

created a simple little php code to populate email with email address and info from a textbox on the form. it originally worked when I was calling to the script from a html form, but once I converted my site to PHP it stopped working. Eventually I would like to put this same info into a Database table but right now I would be content just getting the email to work.
When the form is submitted I get the email address from the customer, but I don't get the info from the textbox. here is my code.
<?php
$email = $_POST['email'];
$message = $_POST['message'];
mail( "sales#sixtoed-design.com", "Service Request", "From: $email",
$message );
header( "Location: http://www.sixtoed-design.com/thankyou.php" );
?>
Like I said it is a very simple code and worked fine before I converted my site completely to PHP.
Below is my code for the form if you need it.
<form method="POST" action="sendmail.php" enctype="multipart/form-data">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input name="" type="submit" value="Send Email">
</form>
You're using the mail function wrong. See the docs.
The 3rd parameter should be the message and you send from as a header in the 4th parameter, so:
mail( "sales#sixtoed-design.com", "Service Request", $message, "From: $email" );
See example 2 in the docs

Categories