MAMP Email PHP difficutly - php

I've placed my .html file and .php file inside the htdocs (MAMP) folder but whenever I click submit on the my webpage to test it, it sends me to this error page .
I'm not sure why it does that.
HTML code:
<form action="pveemail.php" method="POST">
<p>Email Adress: <input type="text" name="email" size="30"></p>
<p>Subject: <input type="text" name="subject" size="30"></p>
<p>Message: </p>
<p><textarea rows="10" cols="50" name="message"></textarea></p>
<input type="submit" name="submit" value="Submit">
</form>
PHP code:
<?php
$from = "test#something.com";
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
mail($email, $subject, $message, $from);
print "Your message was sent";
?>

Related

PHP file name added to URL but not called from html

When using a html form to call php to send an email with the details in the form to an email address specified in the php. The php file name is added to the URL but no email is sent and the page shown in blank.
The website is being hosted on my.ionos.co.uk (1&1) using php 7.3.
<form method="post" action="contact-form.php">
<input class="contact" type="text" name="Name" placeholder="Name">
<input class="contact" type="text" name="Email" placeholder="Your Email Address">
<input class="contact" type="text" name="Subject" placeholder="Subject">
<textarea class="contact" name="Message" rows="10" placeholder="Message"></textarea>
<input class="contact-submit" type="submit" value="Send Message">
</form>
<?php
if(isset($_POST['submit'])) {
$name = $_POST['Name'];
$mailFrom = $_POST['Email'];
$subject = $_POST['Subject'];
$message = $_POST['Message'];
$mailTo = "X#hotmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$Message;
if(mail($mailTo, $subject, $txt, $headers)){
echo "<h1>Mail send successfully</h1>";
} else {
echo "<h1>Mail failed to send<h1>";
}
header("Location: contact.html?mailsend");
}
?>
I'd appreciate it if someone could help, thanks in advance!
Try to change:
if(isset($_POST['submit'])) {
with
if(isset($_POST['Email'])) { //or another field in your form. If you want you can also add in your submit button: name="submit"
Checking out your code seems there is not an input with name submit. So you never enter in the if case.

php localhost mail not receiving

I want to do a "Contact Me" page. I have a problem as I am not receiving the email for testing. First, I used a localhost from my terminal with the following command:
php -S 127.0.0.1:8080
When I access the localhost:8080 the website works fine, but I am not receiving any emails from the contact me. Here is my HTML & php
HTML:
<form class="contact-form" action="contactform.php" method="post">
<input type="text" name="name" class="form-control" placeholder="Name" required><br>
<input type="email" name="email" class="form-control" placeholder="Email" required><br>
<textarea name="message" class="form-control" rows="4" placeholder="Message" required></textarea><br>
<button type="submit" name="submit" class="form-control submit">SEND MESSAGE</button>
</form>
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];
$mailTo = "monbay#inboxbear.com";
$subject = "Form Submission from ".$name;
mail($mailTo, $subject, $msg);
echo '<p>Your message has been sent!</p>';
}
?>

I do not now why my form fails

I wrote this html and php code to send a form, but I do not understand why it fails.
my code :
html
<form action="formulari.php" method="post">
<p>
Nombre:<input name= "name" type="text";>
</p>
<p>
email:<input name= "email" type="text";>
</p>
<p>Comentario:<textarea rows="4" cols="50">
</textarea name= "message"></p>
<input type="submit" value="enviar" >
<input type="reset" value="borrar" >
</form>
php
<?php
$name = $_POST [ 'name'];
$email = $_POST [ 'email'];
$message = $_POST['comentari'];
$to = "email#gmail.com";
$subject = "Formulari_contacte";
mail ( $to, $subject, $message, $email);
header('Location: ../index.html?message=form_submitted');
?>
Can anyone help ?
Try the following:
HTML:
<form action="formulari.php" method="post">
<p>Nombre: <input name="name" type="text"></p>
<p>email: <input name="email" type="text"></p>
<p>Comentario: <textarea rows="4" cols="50" name="message"></textarea></p>
<input type="submit" value="enviar">
<input type="reset" value="borrar">
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "email#gmail.com";
$subject = "Formulari_contacte";
$mail = mail( $to, $subject, $message, $email);
// Check if email is send
if( $mail ) {
header('Location: ../index.html?message=form_submitted');
} else {
echo 'Email not send';
}
?>
I removed the ";" and unnecessary spaces in HTML and PHP. You also had the name of the textarea in the closing tag.
Also note that you are open for injection. Users are able to write some javascript code to you.
If you analyze the html code, in that way you text area will miss the name.
You need to set the name of the text area in the opening tag
<textarea name="comment">Enter text here...</textarea>
Plus your are using a different name in the server side, if you are using name ='message' you will need to use 'message' in to get the POST value
Reference:
http://www.w3schools.com/tags/att_textarea_name.asp
I guess you are unable to fetch textarea value
<form action="formulari.php" method="post">
<p>Nombre:<input name= "name" type="text"></p>
<p>email:<input name= "email" type="text"></p>
<p>Comentario:
<textarea name= "comentari" rows="4" cols="50">
</textarea>
</p>
<input type="submit" value="enviar" >
<input type="reset" value="borrar" >
</form>
Thanks to all that answered my question, with your help and google i have made this formulary that has a anti-spam protection and a system to send the user to a page if the mail has been send.
HTML:
<form action="formulari.php" method="post">
<p>Nombre: <input name="name" type="text"></p>
<p>email: <input name="email" type="text"></p>
<input name="edat" style=" display:none;">
<p>Comentario: <textarea rows="4" cols="50" name="message"></textarea></p>
<input type="submit" value="enviar">
<input type="reset" value="borrar">
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "xavicarreragimbert#gmail.com";
$subject = "Formulari_contacte";
if (!empty($_POST['edat'])){
echo "Lo sentimos el sistema antispam ha detectado que es possiblemente un envio realizado a traves de spam";
}
else{
mail( $to, $subject, $message, $email);
header('Location: ../index.html?message=form_submitted');
}
?>

PHP form redirecting to PHP file itself

I'm trying to get a contact form working, and I'm being redirected to the PHP file itself, and I'm not sure why. I'm fairly new to PHP and I'm not entirely sure what I'm doing wrong. I'd love to be pointed in the right direction. The code is below.
Thanks
HTML:
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
PHP:
<?php
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
?>
This line tells the form what PHP file to send the data to:
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
In particular, it is this part that sends the data to a particular form:
action="form.php"
In fact, this is fine. You can process a form in the same PHP file that contains the form. Just put the PHP form processing at the top:
<?php
if (isset($_POST['Email_Address'] && $_POST['Email_Address'] != ''){
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
EMAIL;
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>
Just remove enctype="text/plain" otherwise your code is correct in HTML and try to echo feedback variable other way is to write all your code above the HTML like below:
<?php
if (isset($_POST['Email_Address'] && !empty['Email_Address']){
$to = 'zack#zfisch.com';
$subject ='Dropset Work Request';
$name = $_POST['Name'];
$company = $_POST['Company'];
$email = $_POST['Email_Address'];
$message = $_POST['Description'];
$message = <<<EMAIL
From: $name
$message
Email: $email
$header = $subject;
if($_POST) {
mail($to, $subject, $message, $header);
$feedback = 'Email sent!';
}
}else{
>?
<p id='feedback'><?php echo $feedback; ?></p>
<form id="contact_us" enctype="text/plain" method="post" action="form.php">
<input class="form_field" type="text" name="Name" placeholder="Full Name">
<br>
<input class="form_field" type="text" name="Company" placeholder="Company Name">
<br>
<input class="form_field" type="email" name="Email_Address" placeholder="Email Address">
<br>
<textarea class="form_field" rows="10" cols="20" name="Description" wrap="hard" placeholder="Project Description"></textarea>
<br>
<p id="required"><i>Please fill in all the fields*</i></p>
<input class="submit" type="submit" value="SUBMIT">
</form>
<?php
}
?>

PHP Mail function didn't work

I have use php contact form for my web site.but it's doesn't work properly.when i fill all the field correctly and submit. it's display error message "Invalid data" .
<?php
$action=$_REQUEST['action'];
if ($action=="")
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30" required/><br>
Your email:<br>
<input name="email" type="email" value="" size="30" required /><br>
Your message:<br>
<textarea name="message" rows="7" cols="30" required></textarea><br> <br>
<input type="submit" value="Send email" class="topbarbtn"/>
</form>
<?php
$subject=$_REQUEST['name'];
$email=$_REQUEST['email'];
$body=$_REQUEST['message'];
}else{
$to = "abc#abc.com";
$subject = $subject;
$from = $email;
$message = $body;
if (($from=="")||($subject=="")||($message==""))
{
echo '<script type="text/javascript">alert("Invalid Details");</script>' ;
} else{
$headers = "From: " . $from . "\r\n";
$body .= $message;
mail($to, $subject, $body, $headers);
}
?>
Like this it works:
<?php
$action=$_REQUEST['action'];
if ($action=="") {?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30" required/><br>
Your email:<br>
<input name="email" type="email" value="" size="30" required /><br>
Your message:<br>
<textarea name="message" rows="7" cols="30" required></textarea><br> <br>
<input type="submit" value="Send email" class="topbarbtn"/>
</form>
<?php
}
else {
$to = "...mail address...";
$subject = $_REQUEST['name'];
$from = $_REQUEST['email'];
$message = $_REQUEST['message'];
if (($from=="")||($subject=="")||($message=="")) {
echo '<script type="text/javascript">alert("Invalid Details");</script>' ;
}
else{
$headers = "From: " . $from . "\r\n";
$body .= $message;
mail($to, $subject, $body, $headers);
}
}
?>
Noticed a flaw in your logics - you try to set $from as an $email, while you don't get a variable $email
in else statement add this lines:
$from = $_REQUEST['email'];
Plus if mail still is not sending you should considerthat some mail servers, such as qmail, will reject your message if it uses \r\n.
So you should try to use just \n or \n\n as a linebreak in a header.

Categories